I have 4 .MAT files that I need to run similar functions on, and plot on same graph. Problem is, if I load first file, it only runs on that file. After the "load" function, there are 163 lines of code to repeat. Some answers I have seen require .Mat files with similar naming convention. File names are: M1_N_o M2_S_o M3_N-b M4_S_b
Asked
Active
Viewed 362 times
1 Answers
0
Only a little info is given. If you could provide the code it will be more helpful. So I am assuming a lot of stuffs.
I am assuming that all files have the same variables with same dimensions
First rename files
M1_N_o.mat,M2_S_o.mat,M3_N-b.mat,M4_S_b.mat
to
M1.mat,M2.mat,M3.mat,M4.mat
Matlab Code:
figure
hold on
numberOfFiles=4;
for fileIndex =1:numberOfFiles
fileName=strcat('M',num2str(fileIndex),'.mat');
load(fileName);
% your 163 lines of code
% do your plots
end
hold off
If you dont want to rename the files then
figure
hold on
fileNames={'M1_N_o.mat' ;'M2_S_o.mat'; 'M3_N-b.mat'; 'M4_S_b.mat'}
for fileIndex =1:size(fileNames,1)
load(fileNames{fileIndex});
% your 163 lines of code
% do your plots
end
hold off

Rijul Sudhir
- 2,064
- 1
- 15
- 19