B=[100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.000;
90.0000 90.0000 90.0000 90.0000 110.0000 90.0000 90.0000 90.0000 110.0000 110.0000 110.0000 110.0000 110.0000 110.0000 110.0000 110.000;
81.0000 81.0000 81.0000 99.0000 99.0000 81.0000 99.0000 99.0000 99.0000 99.0000 121.0000 121.0000 121.0000 121.0000 121.0000 121.000;
72.9000 72.9000 89.1000 89.1000 89.1000 89.1000 89.1000 108.9000 89.1000 108.9000 108.9000 108.9000 133.1000 133.1000 108.9000 133.100;
65.6100 80.1900 80.1900 80.1900 80.1900 98.0100 98.0100 98.0100 98.0100 98.0100 98.0100 119.7900 119.7900 119.7900 119.7900 146.410]
lastRow = B(end, :)
[rows, columns] = size(B)
pricesToSearchFor = unique(lastRow)
for k = 1 : length(pricesToSearchFor)
thisPrice = pricesToSearchFor(k);
fprintf('Searching all columns for price $%.2f.\n', thisPrice);
columnCounter = 1;
for column = 1 : columns
thisColumn = B(:, column);
lastIndexInColumn = find(thisColumn == thisPrice, 1, 'last');
if ~isempty(lastIndexInColumn)
fprintf('Found %.2f at row %d of column %d of B.\n', ...
thisPrice, lastIndexInColumn, column);
A(k, columnCounter) = mean(thisColumn(1:lastIndexInColumn));
columnCounter = columnCounter + 1;
end
end
end
A
Best Answer