want to change what data I am plotting by text name.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Riley Duffens
am 13 Jun. 2023
Kommentiert: Riley Duffens
am 13 Jun. 2023
I am needing to plot many things from a .mat file but do not want to copy and paste the same code 30 times. I am wanting to set a varible such as 'CylinderPressure' and call it later. This works for everything but plotting. How can I change the 'CylinderPressure' so whats in it (the varible in question) can be referenced in plotting. In the end I want to just change the var variable to change what I am plotting. I atached the code I want to modify. Any help would be greatly apreciated.
var = 'CylinderPressure';
hold on
load('march.mat', var)
plot(CylinderPressure)
load('Feb.mat', var)
plot(CylinderPressure)
title(var)
legend('march','feb')
hold off
0 Kommentare
Akzeptierte Antwort
Stephen23
am 13 Jun. 2023
Bearbeitet: Stephen23
am 13 Jun. 2023
Do NOT load directly into the workspace, always LOAD into an output variable (which is a scalar structure).
Then simply use this syntax:
var = 'CylinderPressure';
S1 = load('march.mat',var);
S2 = load('Feb.mat' ,var);
V1 = S1.(var);
V2 = S2.(var);
hold on
plot(V1)
plot(V2)
title(var)
legend('march','feb')
hold off
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations 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!