combine 30.mat file having 1*15 matrix (Each .mat file having 1 row and 15 columns) to one .mat file

1 次查看(过去 30 天)
Hallo ,
I have a .mat files of 30 with 1*15 matrix, I want to combine all these 30 files to one .mat file with 1*450 matrix. Can you please help me with how to do this steps.
I have done and tried many of the examples with the existing codes in Mathwork but couldnot make it to work.
Can any one help me.
I have attached 6 .mat files as a reference.
Thankyou in advance

采纳的回答

Stephen23
Stephen23 2020-2-25
编辑:Stephen23 2020-2-25
The best approach is to follow the examples in the MATLAB documentation:
N = 30;
C = cell(1,N); % preallocate
for k = 1:N
F = sprintf('Si_%u.mat',k);
S = load(F);
C{k} = S.Si; % using the same field/variable name = very good data design!
end
M = [C{:}]; % concatenate
save('Si.mat','M')
See also:
  3 个评论
Stephen23
Stephen23 2020-2-25
编辑:Stephen23 2020-2-25
"It is not in image format..."
Nothing in my answer is related to images, so what is your comment related to?
"Actually in the .mat file the variable which contains matrix 1*13 the name of the variable is also Si"
Yes I know, because I looked at the contents of all of your sample files before writing and testing my code.
"there is no path provided how can i use this code to carry on with different .mat files."
My code already works with multiple .mat files in the current folder. I know this because I tested it.
You did not specify the lcoation of the files, but if you want to import the files from other location then simply add fullfile to generate the correct absolute/relative filename.
Or simply change the current directory.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Scope Variables and Generate Names 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by