Autmating a matlab script

2 Ansichten (letzte 30 Tage)
Bayram Akpinar
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
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)
Bayram Akpinar
Bayram Akpinar am 3 Mär. 2021
I tried but couldn't find it. I will search better again thank you very much.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KSSV
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
Bayram Akpinar
Bayram Akpinar am 3 Mär. 2021
Thank you very much I will try it immediately
!
Bayram Akpinar
Bayram Akpinar am 3 Mär. 2021
I suffer some problems with the code with the dir I copy my pathway and past it inside the function
as dir('/Users/Bayram/Desktop/Master Project/naamloze map\*.doc')
it gives me the error' No matches for pattern '/Users/Bayram/Desktop/Master Project/naamloze map\*.doc'.'
and when I try to run the the script you gave me I can't get anything.
The problem that I think I have is that the files that I have do not have .doc or anything else. It is just named as data1. It all is a document file. I do not know if that matters?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by