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

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Stephen23
Stephen23 el 25 de Feb. de 2020
Editada: Stephen23 el 25 de Feb. de 2020
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 comentarios
Stephen23
Stephen23 el 25 de Feb. de 2020
Editada: Stephen23 el 25 de Feb. de 2020
"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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Scope Variables and Generate Names en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by