Indexing into a type I don't recognize
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Douglas Farinelli
il 30 Ott 2019
Commentato: Walter Roberson
il 30 Ott 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 Commenti
Stephen23
il 30 Ott 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
il 30 Ott 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
Risposta accettata
Stephen23
il 30 Ott 2019
Modificato: Stephen23
il 30 Ott 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}
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!