필터 지우기
필터 지우기

If statement not working

조회 수: 1 (최근 30일)
Maria Ali
Maria Ali 2021년 5월 21일
편집: the cyclist 2021년 5월 21일
I have a struct variable that has 20 fields. 11 f them are row matrices of about 24536 x 1 double, while the remaining are either characters, strings and arrays of different dimensions.
i am using if statement to compare the size of each field but it is still giving me some fields that should be omitted.
Code:
b=size(second{1,1}); % second is the cell array and i am using the size of first cell array value
if size(second{i,1}) == b
statements
else
remove field
end
but it is still not removing some of the fields that do not have same dimensions
  댓글 수: 1
the cyclist
the cyclist 2021년 5월 21일
편집: the cyclist 2021년 5월 21일
Can you upload the data (or a small, representative sample) in a MAT file?
Also, in the statement
if size(second{i,1}) == b
what is i? Are you doing this inside a for loop? It would be best if you included a self-contained piece of code that we can run.

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

답변 (1개)

Walter Roberson
Walter Roberson 2021년 5월 21일
편집: Walter Roberson 2021년 5월 21일
use isequal to compare items that might not be the same size. That is, for arrays with more than two dimensions size() would not be of length 2.

카테고리

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

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by