changing elements of a multidimensional array using matlab
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!