Transpose a structure with named fields ?
46 ビュー (過去 30 日間)
古いコメントを表示
I have a struct that looks like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/321220/image.png)
i.g. labeled fields
I have been trying to apply this example:
% Fake data
s(1).f = rand(1,100);
s(2).f = rand(1,100);
s(3).f = rand(1,100);
c = arrayfun(@(x)x.f.', s, 'UniformOutput', 0);
s = cell2struct(c, 'f');
but I think it doesn't work becuase I have labeled feilds.
Any ideas?
1 件のコメント
Stephen23
2020 年 6 月 24 日
編集済み: Stephen23
2020 年 6 月 24 日
"Any ideas?"
Your screenshot shows a scalar structure with multiple fields.
Your example code has a non-scalar structure with one field.
It is not clear how that example would apply to the scalar structure shown in your screenshot.
You could use structfun like Mehmed Saad showed, or simply loop over the fieldnames:
採用された回答
Mehmed Saad
2020 年 6 月 24 日
if all of them are scalar then this will work
s_mod=structfun(@transpose,s,'UniformOutput',false)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!