フィルターのクリア

How to inverse all vectors in a struct

12 ビュー (過去 30 日間)
Fredrik
Fredrik 2013 年 4 月 3 日
Hi, I have several structs with vectors in all of them. For some reason I have all vectors in wrong order. An example could be that they are 1 4 7 9 8 but I would like it to be 8 9 7 4 1. I wonder if there is a way to inverse all of the vectors inside a struct without having to call Structure.A, Structure.B etc as it would both be time consuming, line consuming and inconvenient!
I guess I am looking for something like fliplr(Structure) instead of fliplr(Structure.A)
All help is much appreciated! Fredrik

回答 (2 件)

Matt Kindig
Matt Kindig 2013 年 4 月 3 日
編集済み: Matt Kindig 2013 年 4 月 3 日
Structure= structfun(@fliplr, Structure, 'UniformOutput', false)

Jan
Jan 2013 年 4 月 3 日
Compare the structfun approach with a loop:
f = fieldnames(S);
for k = 1:length(f)
af = f{k};
S.(af) = S.(af)(end:-1:1);
end
Inside structfun a loop is required also. Calling the function fliplr() has a certain overhead, so reverting the vectors locally is an advantage.

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by