Indexing into a type I don't recognize

1 visualización (últimos 30 días)
Douglas Farinelli
Douglas Farinelli el 30 de Oct. de 2019
Comentada: Walter Roberson el 30 de Oct. de 2019
Inherited code ... have a struct with an array of fields. One of the fields is called tag which is seems to be struct of strings (if I hover over the field only see the 1st value), if I use the command window then the output is a list of answers of type string. I'm able to search this list via ii = find(strcmp({ext_header.tag},'FS')==1) ... I now want to access the associated value in ext_header.value. If I create a cell array c = {ext_header.value}; then I can access the desired value using cell2mat(c(ii)).
This seems akward to me ... i.e. don't wish to create the cell array ... but I haven't been able to directly index into ext_header.value?
  5 comentarios
Stephen23
Stephen23 el 30 de Oct. de 2019
"have a struct with an array of fields"
But your examples show a structure array with scalar fields. Please show the output of this command:
size(ext_header)
Walter Roberson
Walter Roberson el 30 de Oct. de 2019
c = [ext_header.value];
c(ii)
But Stephen's idea to use ext_header(ii).value is a good one for the case of scalar ii

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 30 de Oct. de 2019
Editada: Stephen23 el 30 de Oct. de 2019
Use indexing to get any elements you want from a structure array:
ext_header(ii).value
Note that your attempt using an intermediate cell array would be much simpler and more efficient using the correct cell indexing (rather than that very awkward and slow cell2mat):
c = {ext_header.value};
c{ii}

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by