find if the variable exists in a given cell-structure
22 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Megha
am 16 Aug. 2018
Bearbeitet: Stephen23
am 16 Aug. 2018
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 Kommentar
Stephen23
am 16 Aug. 2018
Bearbeitet: Stephen23
am 16 Aug. 2018
"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).
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!