insert zero in chosen column of matrix randomly

1 次查看(过去 30 天)
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];

采纳的回答

madhan ravi
madhan ravi 2019-9-19
编辑:madhan ravi 2019-9-19
ix = 1:2:size(A,1);
A(ix(randi(numel(ix),1)),3)=0

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by