How to import different data in for loop ?
Show older comments
Hello everybody, Thank you for reading this
I have a simple code for generating efficiency map for electric machine from data file taht contains all needed variables(Speed, Shaft_Torque, Total_Loss)
%%%%%
figure;
contourf(Speed,Shaft_Torque,Total_Loss,45,'EdgeColor','none','Showtext','on');
box on;
grid on;
xlabel('Speed [rpm]','FontSize',20);
ylabel(' Torque [N.m]','FontSize',20);
%title('Rendement');
%axis([0 14000 -300 300 ]);
colorbar ('FontSize',20);
%%%%%%
Now considering that I have data files of different electric machines, I want to plot efficiency map for every machine
%Definition of different machines
Machine_1=load('M3_MSAP_hairpin_2layers_265_500_180_120');
Machine_2=load('M3_MSAP_stranded_220_450_180_120.mat');
Machine_3=load('M3_MSAP_stranded_265_450_180_120.mat');
Machine_4=load('M3_MSAP_stranded_350_450_180_120.mat');
Machine_5=load('M3_MSAP_stranded_450_450_180_120.mat');
Machine_6=load('M3_MSRB_HP_220_450_94_106.mat');
Machine_7=load('M3_MSRB_HP_265_450_94_106.mat');
Machine_8=load('M3_MSRB_HP_350_450_94_106.mat');
Machine_9=load('M3_MSRB_HP_450_450_94_106.mat');
How can I create a for loop that calls a different machine in every iteration (from 1 to 9) ?!
Thank you for your help !
Answers (1)
Perhaps something like this:
% i'm assuming that first filename has an extension
fnames={'M3_MSAP_hairpin_2layers_265_500_180_120.mat'; ...
'M3_MSAP_stranded_220_450_180_120.mat'; ...
'M3_MSAP_stranded_265_450_180_120.mat'; ...
'M3_MSAP_stranded_350_450_180_120.mat'; ...
'M3_MSAP_stranded_450_450_180_120.mat'; ...
'M3_MSRB_HP_220_450_94_106.mat'; ...
'M3_MSRB_HP_265_450_94_106.mat'; ...
'M3_MSRB_HP_350_450_94_106.mat'; ...
'M3_MSRB_HP_450_450_94_106.mat'};
% use an array instead of a pile of variables
Machines=cell([numel(fnames) 1]);
for f=1:numel(fnames)
Machines{f}=load(fnames{f});
end
Categories
Find more on Switches and Breakers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!