changing elements of a multidimensional array using matlab
Show older comments
Hey guys, Im kind of lost. I am making a m*n zero matrix. I want to change each element into either 1,2 or 3. If the array is 1 by n i can do it but i can't do it for m*n i am using for loops this is what i would did.
x=zeros(1,randi(10)) n=length(x) for m=1:n x(m)=randi(3) end This works for 1*n but what would i do if its like 2 by n or bigger i tried this
x=zeros(2,randi(10)) [r,c]=size(x) for m=1:r for p=1:c x(p)=randi(3) end x(m)=randi(3) end this only changes the first 3 elements and the 1st two of the second row. Please help thanks
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!