Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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

Réponse acceptée

Stephen23
Stephen23 le 25 Fév 2020
Modifié(e) : Stephen23 le 25 Fév 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 commentaires
Stephen23
Stephen23 le 25 Fév 2020
Modifié(e) : Stephen23 le 25 Fév 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Scope Variables and Generate Names dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by