Autmating a matlab script
3 views (last 30 days)
Show older comments
Hello all, I am trying to run a matlab script for a dataset. For this I have to change the script for each data file. For example below is my script and my datasets goes from data 1 till data 40. I want to automate this and get all the graphs at one time. Is this possible and how can I do this? Thank you in advance.
load data40 ; %%change the number after data into the desired data
frequency = data40(:,1); %%name the variable 1st collumn to frequency
zabsolute = data40(:,2); %%name the variable 2nd collumn to zabsolute
degree = data40 (:,3); %%name the variable 3rd collumn to degree
x= frequency * 1000; %% frequency is given in KHz multiply with 1000
y1 = zabsolute .* cosd(degree); %% formula to calculate the imaginair component of impedance
y2 = zabsolute .* sind(degree); %% formula to calculate the real component of impedance
subplot(2,1,1);
plot(x,y1),
title ( ' Resistance ' );
xlabel ( ' Frequency (Hz)');
ylabel ( ' Re Z');
subplot (2,1,2);
plot (x,y2);
title ( ' Reactance' );
xlabel ( ' Frequency (Hz)');
ylabel ( ' Img Z')
2 Comments
KALYAN ACHARJYA
on 3 Mar 2021
There are many similar questions, which have already been answered, please do a search with "Call Multiple Image + MATLAB" (Google)
Accepted Answer
KSSV
on 3 Mar 2021
Edited: KSSV
on 3 Mar 2021
matFiles = dir('*.mat') ;
N = length(matFiles) ;
for i = 1:N
load(matFiles(i).name) ; % you need to see how the variables are named here
frequency = data(:,1);
zabsolute = data(:,2);
degree = data(:,3);
x= frequency * 1000; %% frequency is given in KHz multiply with 1000
y1 = zabsolute .* cosd(degree); %% formula to calculate the imaginair component of impedance
y2 = zabsolute .* sind(degree); %% formula to calculate the real component of impedance
figure(i)
subplot(2,1,1);
plot(x,y1),
title ( ' Resistance ' );
xlabel ( ' Frequency (Hz)');
ylabel ( ' Re Z');
subplot (2,1,2);
plot (x,y2);
title ( ' Reactance' );
xlabel ( ' Frequency (Hz)');
ylabel ( ' Img Z')
end
More Answers (0)
See Also
Categories
Find more on Printing and Saving 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!