If I am trying to write a "while" loop for while the bottom row of a matrix has only one non-zero value, what would I write after the "while" to specify only that condition?

조회 수: 4 (최근 30일)
Lets say I have a matrix of:
zeros(6,7)
And I want to run a function only as long as there is one non-zero element in the 6th row. How would I do that until a second non-zero element is placed there?

채택된 답변

Image Analyst
Image Analyst 2017년 4월 27일
Try this while m is your matrix:
while nnz(m(end, :)) == 1
% Do something
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by