Vertically concatenate fields in a structure

3 ビュー (過去 30 日間)
Luis Lopez
Luis Lopez 2016 年 4 月 14 日
回答済み: Luis Lopez 2016 年 4 月 14 日
How can I concatenate every field to get a 1 x 1 structure with the same number of fields in a new structure. I've tried this: myVars is a cell array with field names.
for i=1:length(x)
for j=1:length(myVars)
s.(myVars{1,j})=[x(1).(myVars{1,j});x(2).(myVars{1,j});x(3).(myVars{1,j})]; % read/concatenate
end
end
but after run I got this Error using horzcat Dimensions of matrices being concatenated are not consistent.
Which could be a right way to solve this? Thanks

回答 (1 件)

Luis Lopez
Luis Lopez 2016 年 4 月 14 日
Solved.
for i=1:length(myVars)
s.(myVars{1,i}) = vertcat(x.(myVars{1,i})); % read/concatenate
end

カテゴリ

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