How to concatenate variables in different matlab files?
古いコメントを表示
I have two mat files with identical number of variables.
In file1.mat
Variables
Time [100X1] double
Force [100x1] double
In file2.mat
Variables
Time_1 [90X1] double
Force_1 [90x1] double
I would like to vertically concatenate these variables. The suffix '_1' is constant for all variables in one file, but changes from file to file.
Thanks
採用された回答
その他の回答 (2 件)
Aaditya Kalsi
2012 年 9 月 24 日
You can do this quite simply:
% load initial data
filedata = load('file1.mat');
Time = filedata.Time;
Force = filedata.Force;
num_more_files = 2 % say i had two more mat-files
for i = 1:num_more_files
var_appended_str = ['_' num2str(i)];
filename = ['file' num2str(i) '.mat'];
filedata = load(filename);
Time = [Time; filedata.(sprintf(['Time' var_appended_str]))];
Force = [Force; filedata.(sprintf(['Force' var_appended_str]))];
end
This code has not been tested but you get the idea.
Hope this helps.
カテゴリ
ヘルプ センター および File Exchange で Workspace Variables and MAT Files についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!