MATLAB Answers

insert zero in chosen column of matrix randomly

5 views (last 30 days)
Na
Na on 19 Sep 2019
Edited: madhan ravi on 19 Sep 2019
I have
A=[
1 2 1 4
3 4 1 4
4 5 1 5
5 7 1 6
7 9 1 9];
I want to put zero for only one entery in column 3 randomly.
result shoud be
A=[
1 2 0 4
3 4 1 4
4 5 1 5
5 7 1 6
7 9 1 9];
or
A=[
1 2 1 4
3 4 1 4
4 5 0 5
5 7 1 6
7 9 1 9];
or
A=[
1 2 1 4
3 4 1 4
4 5 1 5
5 7 1 6
7 9 0 9];

  0 Comments

Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 19 Sep 2019
Edited: madhan ravi on 19 Sep 2019
ix = 1:2:size(A,1);
A(ix(randi(numel(ix),1)),3)=0

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.