Indexing into a type I don't recognize
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
Stephen23
2019 年 10 月 30 日
"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
2019 年 10 月 30 日
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
採用された回答
Stephen23
2019 年 10 月 30 日
編集済み: Stephen23
2019 年 10 月 30 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!