Autmating a matlab script
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bayram Akpinar
am 3 Mär. 2021
Kommentiert: Bayram Akpinar
am 3 Mär. 2021
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 Kommentare
KALYAN ACHARJYA
am 3 Mär. 2021
There are many similar questions, which have already been answered, please do a search with "Call Multiple Image + MATLAB" (Google)
Akzeptierte Antwort
KSSV
am 3 Mär. 2021
Bearbeitet: KSSV
am 3 Mär. 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
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Printing and Saving finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!