i was trying to run three different mat files some reason only the first one is read by matlab

6 views (last 30 days)
load 'testprop1.mat'
eff1= eff;
J1 = J;
t1 = t;
q1 = q;
load 'testprop2.mat'
eff2= eff;
J2 = J;
t2 = t;
q2 = q;
load 'testprop3.mat'
eff3= eff;
J3 = J;
t3 = t;
q3 = q;
plot(J1,t1,J2,t2,J3,t3);

Answers (1)

Jan
Jan on 20 Mar 2022
It is a frequent cause of unexpected behavior, that MAT files contain other variables that the user assumes. Therefore it is recommended to catch the output of load in a variables. This supports the debugging:
data1 = load('testprop1.mat');
eff1= data1.eff;
J1 = data1.J;
t1 = data1.t;
q1 = data1.q;
data2 = load('testprop2.mat');
eff2= data2.eff;
J2 = data2.J;
t2 = data2.t;
q2 = data2.q;
data3 = load('testprop3.mat');
eff3= data3.eff;
J3 = data3.J;
t3 = data3.t;
q3 = data3.q;
plot(J1,t1,J2,t2,J3,t3);
What do you observe now?
Beside the easier dbugging, this let Matlab run faster also, because calling load to import the data directly into the workspace impedes the JIT acceleration.
  3 Comments
sujan raj kolachhapati
sujan raj kolachhapati on 20 Mar 2022
it looks like matlab is plotting the data available from workspace, if i clear workspace it wont recognise any variable
Jan
Jan on 20 Mar 2022
Of course clearing the workspace removes the variables. This is the purpose.
Reference to non-existent field 'eff'.
This means, that the MAT file does not contain this variable.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!