필터 지우기
필터 지우기

Comparing an array of cells in a matrix

조회 수: 1 (최근 30일)
Lev Mihailov
Lev Mihailov 2019년 7월 9일
댓글: Rik 2019년 7월 9일
Hello! I need to compare values ​​with each other in cell arrays
for redit = 1:length(xintegra)-1
if EE1{redit}-100>= EE1{redit+1};
E1{redit}=0;
else EE1{redit}+100 <= EE1{redit+1};
E1{redit}=EE1{redit};
end
end
You give an error "Index exceeds matrix dimensions."
Help me fix
  댓글 수: 2
Rik
Rik 2019년 7월 9일
Comment posted as answer by Praveen:
What is the input Xintegra?
Rik
Rik 2019년 7월 9일
Reply by Lev Mihailov:
the minimum value of my matrix = 11003, EE1 this is an indicator of where it is located.

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

답변 (1개)

Roy Kadesh
Roy Kadesh 2019년 7월 9일
If you want loop through all values of EE1, then you can use the code below.
for redit = 1:numel(EE1)-1
if EE1{redit}-100>= EE1{redit+1}
E1{redit}=0;
elseif EE1{redit}+100 <= EE1{redit+1} %did you mean elseif?
E1{redit}=EE1{redit};
end
end
If you want to catch the case where redit is larger than the numer of elements in EE1, you can fill in the code below.
for redit = 1:numel(xintegra)-1
if (redit+1)>numel(EE1)
%do something else
else
if EE1{redit}-100>= EE1{redit+1}
E1{redit}=0;
elseif EE1{redit}+100 <= EE1{redit+1} %did you mean elseif
E1{redit}=EE1{redit};
end
end
end
  댓글 수: 1
Rik
Rik 2019년 7월 9일
If there are indeed only numeric values inside that cell array, it is probably much faster to convert it to a double and use logical indexing to create the output.

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by