Borrar filtros
Borrar filtros

want to change what data I am plotting by text name.

1 visualización (últimos 30 días)
Riley Duffens
Riley Duffens el 13 de Jun. de 2023
Comentada: Riley Duffens el 13 de Jun. de 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

Respuesta aceptada

Stephen23
Stephen23 el 13 de Jun. de 2023
Editada: Stephen23 el 13 de Jun. de 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

Más respuestas (0)

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by