Clear Filters
Clear Filters

select one element in each row but not the same column

2 views (last 30 days)
Hi everyone I have matrices 3*3 A= [1 2 3; 4 5 6; 7 8 9] and B=zeros(3,3) I want to choose one element in each row, for example if i choose A(1,1), the matrice of B(1,1) change its value to 1,

Accepted Answer

Jos (10584)
Jos (10584) on 7 Feb 2019
A= [1 2 3; 4 5 6; 7 8 9]
ix = logical(eye(size(A))) % one element per row
ix = ix(:,randperm(size(ix,2))) % randomize accross columns
% this ix matrix is now already your B, I think
B = zeros(size(A)) ; % create B
B(ix) = 1 ;

More Answers (0)

Categories

Find more on Mathematics and Optimization in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!