Create a vector with data from a structure named with the field name

4 ビュー (過去 30 日間)
Luis Lopez
Luis Lopez 2016 年 4 月 13 日
編集済み: Stephen23 2019 年 6 月 19 日
Hi, I want to créate a vector, currently I've named manually using the next way:
Actual_Gear_Ratio = [];
>> for i=1:length(x)
Actual_Gear_Ratio=[Actual_Gear_Ratio; x(i).Actual_Gear_Ratio]; % read/concatenate
end
What I want to avoid is the necessity to name every vector, I have a cell array (myVars) with all the variable names but I haven't be able to créate all the vectors automatically. I've tried things like this:
for i=1:length(x)
for j=1:length(myVars)
myVars(1,j)=[myVars(1,j); x(i).myVars(1,j)]; % read/concatenate
end
end
Hope you can help me. Thanks
  1 件のコメント
Stephen23
Stephen23 2016 年 4 月 13 日
編集済み: Stephen23 2019 年 6 月 19 日
@Luis Lopez: the structure is a good form of storage. Don't create lots of separate variables: they would be much more difficult to access than what you have now.

サインインしてコメントする。

回答 (2 件)

Luis Lopez
Luis Lopez 2016 年 4 月 14 日
Oh, I guess so I have to start working with structures. Thanks for your answer is good to know why must be avoided this kind of practices.

Luis Lopez
Luis Lopez 2016 年 4 月 14 日
How can I concatenate every field to at the end get a 1 x 1 with same original 15 fields in a new structure? i guess this could be really simple but I couldn't find the solution.
Thanks

カテゴリ

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