Error in my code

3 次查看(过去 30 天)
Igina
Igina 2013-6-19
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!

采纳的回答

Jonathan Sullivan
Jonathan Sullivan 2013-6-19
Just do
MAT(MAT == 0) = 6;
  1 个评论
Igina
Igina 2013-6-19
Thanks! I am actually not familiar with such smart solutions!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Language Fundamentals 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by