find if the variable exists in a given cell-structure

I have structure-data within a cell. Now I would like to check the condition in each cell if the particular variable exists or not?
So, i tried something like,
str = (['data{1,' num2str(i) '}.m_PA_in_out1']);
if exist(str,'var')==1
disp('>>>> YES')
else
disp('no variable')
end

댓글 수: 1

Stephen23
Stephen23 2018년 8월 16일
편집: Stephen23 2018년 8월 16일
"Now I would like to check the condition in each cell if the particular variable exists or not?"
Neither cells nor structures contain "variables", although tables do use this nomenclature. Structures have fields. Are you actually trying to test if the structure contains a particular field ? I.e. to check if the structure in data{...} contains the field m_PA_in_out1 ?
Note that if all structures have the same fields then you would be better off using a non-scalar structure:
As I wrote in my comment to your earlier question, the approach you are using is going to be slow, complex, and buggy (exactly as you are finding out).

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

 채택된 답변

Stephen23
Stephen23 2018년 8월 16일
편집: Stephen23 2018년 8월 16일
Use isfield to test if a structure has a particular field:
isfield(data{1,i},'m_PA_in_out1')

댓글 수: 2

Just tried the same
isfield(data{1,i},'m_PA_in_out1')
it does not identify the variable and ends the loop as it is.
oh okay! sorry I put
isfield(data{1,i},'.m_FPSA_in_out1')
.Dot before m_FPSA_in_out1.
ANyway, Thanks

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

질문:

2018년 8월 16일

편집:

2018년 8월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by