Autmating a matlab script

3 次查看(过去 30 天)
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 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2021-3-3
There are many similar questions, which have already been answered, please do a search with "Call Multiple Image + MATLAB" (Google)
Bayram Akpinar
Bayram Akpinar 2021-3-3
I tried but couldn't find it. I will search better again thank you very much.

请先登录,再进行评论。

采纳的回答

KSSV
KSSV 2021-3-3
编辑:KSSV 2021-3-3
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 个评论
Bayram Akpinar
Bayram Akpinar 2021-3-3
Thank you very much I will try it immediately
!
Bayram Akpinar
Bayram Akpinar 2021-3-3
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?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by