How can I replace the maximum value in every column in matrix A (38 x 13390) by 1 in matrix B (38 x 13390) in the same cell of every column in matrix A

6 views (last 30 days)
I have a matix A which contents of 38 rows and 13390 colomns I need to find the maximum value in every column and specify the cell's location, at the same location in matrix B I want to write 1 and the rest of the column's cells I want them to be zeros.

Accepted Answer

Sindar
Sindar on 18 Feb 2020
A=rand(38,13390);
% find the max elements M for each column and the indices I
% 'linear' returns linear indices instead of row number
[M,I] = max(A,[],1,'linear')
% start B off empty
B = zeros(38,13390);
% fill the location of each max from A with a 1
B(I) = 1;

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!