필터 지우기
필터 지우기

Embedded if loop in for loop

조회 수: 1 (최근 30일)
Cside
Cside 2020년 2월 23일
댓글: Cside 2020년 2월 24일
Hello! I have a 120x2 matrix and would need to match for every row, if there is a common number that appears in both columns. Eventually, I want my results to show the common number(s) that appears in every row (if any) in a cell. Right now, the if loop accounts for all the numbers in the box i.e for the second row, it is comparing [1;2;3;6;8;9] and [9], and the if loop will give me a over =0. However, 9 is a common number in both columns, and I want it to be reflected. How may I code for this?
Thank you! :) attached Spfcfef for ease too
for n = 1:120
if cell2mat(Spfcfef(n,1)) == cell2mat(Spfcfef(n,2))
over = 1
else
over = 0
end
end

채택된 답변

Sai Bhargav Avula
Sai Bhargav Avula 2020년 2월 23일
Hi,
The first column is an array and you are checking if an element is present in it for such cases you need to use ismember function.
Hope this helps!
  댓글 수: 1
Cside
Cside 2020년 2월 24일
yes it does :) thank you!

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

추가 답변 (0개)

카테고리

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