I can combine for loop outputs

조회 수: 3 (최근 30일)
Oktay Ahmadli
Oktay Ahmadli 2020년 12월 6일
댓글: Oktay Ahmadli 2020년 12월 6일
this is my code. i create a function that when input limit is given it says how many elements of matrix is greater that the limit. i want to get output = 2 but because of for loop it gives it sepereatky. How to sum them?

채택된 답변

VBBV
VBBV 2020년 12월 6일
k = 0;
for i = 1:m
for j = 1:n
if A(i,j) > limit
k = k+1;
end
end
end
disp(k)
  댓글 수: 1
Oktay Ahmadli
Oktay Ahmadli 2020년 12월 6일
Thank you. i tried this before i dk it didnt work that time. i accept this answer

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2020년 12월 6일
When A is a variable rather than a function, length(A(i,j)) is always going to be 1 when i and j are both scalar (well, except for cases where i or j are out of bounds for the array size.)
Instead of disp() anything at that point, add 1 to a counter. Later return the counter or display the counter.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by