Error in my code

1 Ansicht (letzte 30 Tage)
Igina
Igina am 19 Jun. 2013
Hi, everybody, MATLAB tells me that this code in the 3rd "while" has a problem (MAT is a matrix):
ir=1;
while(ir<=length(MAT(1,:)))
ic=1;
while(ic<=length(MAT(:,1)))
while(MAT(ir,ic)==0)
MAT(ir,ic)=6;
end
ic=ic+1;
end
ir=ir+1;
end
Just to be more precise: with this code I want to replace the zero entries of the matrix MAT with the number 6. Thank you!

Akzeptierte Antwort

Jonathan Sullivan
Jonathan Sullivan am 19 Jun. 2013
Just do
MAT(MAT == 0) = 6;
  1 Kommentar
Igina
Igina am 19 Jun. 2013
Thanks! I am actually not familiar with such smart solutions!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by