Checking whether a field is present in cell.

3 visualizaciones (últimos 30 días)
Natalie
Natalie el 3 de Oct. de 2013
Comentada: Natalie el 3 de Oct. de 2013
I've got some variables stored in a cell but not all of the fields are present in every entry of the cell, so I need to check whether a particular field is present before I use the values contained in it. So I've got...
for m=1:NumYears
for p=1:NumTechnologies
if exist(TriangularVariables{m,p}.ReconstructedVariables)
disp('exists')
end
end
end
but Matlab returns the error 'Reference to non-existent field 'ReconstructedVariables''. I thought perhaps it was because I was referring to the contents of the cell rather than the name so I also tried round brackets but then Matlab complained that I wasn't referencing properly.
Thanks in advance.
  1 comentario
Natalie
Natalie el 3 de Oct. de 2013
All sorted now I used...
if isfield(TriangularVariables{m,p}, 'ReconstructedVariables')
instead. Still not exactly clear why the other way didn't work so I would be grateful if somebody could explain. Thanks.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by