Error using function load
8 views (last 30 days)
Show older comments
Dear community I am doing something wrong with my script. I am trying to automize my script. The load function is given me a error. I dont know exaclty what I am doing wrong. My dataset is as follow from data1 till data40. From each data I want to get a plot and name the plots for data1 --> data1. Can someone please help me out.
As shown below
matfiles= dir ('data*')
N = length(matfiles) ;
for i = 1:N
load(matfiles(i).) ; % I want to load for example data 1 of the dataset and then further naming the variables of each dataset. giving the
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
0 Comments
Accepted Answer
Stephen23
on 10 Mar 2021
Edited: Stephen23
on 10 Mar 2021
load(matfiles(i).)
% ^^ You forgot to write the fieldname.
Note that you should specify the file extension and for more reliable code always load into an output variable:
S = dir('data*.mat');
for k = 1:numel(S)
D = load(S(k).name);
frequency = D.data(:,1);
zabsolute = D.data(:,2);
degree = D.data(:,3);
..
end
6 Comments
More Answers (0)
See Also
Categories
Find more on Workspace Variables and MAT Files 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!