Reputation: 13
So basically I'm looking for something like arrayfun(@(value, rowIdx, colIdx), matrix)
.
I need to create one matrix from another based on it's values and their indexes, is there a way to avoid for-loops?
Upvotes: 1
Views: 370
Reputation: 65460
You can create matrices for the row and column indices using meshgrid
and the size of your matrix. You can then use all three of these matrices to calculate the result.
[col_index, row_index] = meshgrid(1:size(matrix, 1), 1:size(matrix, 2));
% Now do some calculations using that
new_matrix = matrix + row_index * col_index;
Upvotes: 1