MATLAB structure merge

早过忘川 提交于 2019-12-04 09:47:05

Sorry, I had misunderstood your question - here a second try.

Maybe there is an easier way, but you can get a list of all fields in data using mynames=fieldnames(data). You can then loop through them all and assign them to a common struct like this:

combineddata.(mynames{i})=[data1.(mynames{i}); data2.(mynames{i}); data3.(mynames{i})];

Here's one solution using the functions FIELDNAMES, CELLFUN, and CELL2STRUCT:

data = [data1 data2 data3 data4];    %# Create a structure array of your data
names = fieldnames(data);            %# Get the field names
cellData = cellfun(@(f) {vertcat(data.(f))},names);  %# Collect field data into
                                                     %#   a cell array
data = cell2struct(cellData,names);  %# Convert the cell array into a structure
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!