Plot with dot notation as an updating variable
显示 更早的评论
How to make the plot command accept a variable name as part of the dot notation ?
See my code below
% Cam plots
% goal: to only have one plot file for several sets of data
%Data files (.mat)have different index, (DataFile1, DataFile2, etc)
%There are 3 sets of data in each data file.
%In DataFile1 it is Set11, Set12 and Set13
%In DataFile2 it is Set21, Set22 and Set23 , etc
%The variable names of the data columns are the same in all sets, meaning Set11,
%Set21, Set31, etc have same variable name (Dures,EMoteurTreuilAbar, etc)
%so the plot command must be able to use the updated data set names
close all
clear
load('DataFile1.mat'); % could also be DataFile2, DataFile3, etc
WS_vars = who('-file','DataFile1.mat');% Read names of data sets
VarToPlot=string(WS_vars{1}); % take the name of Set11
%I want the plot command to be able to use different values for 'VarToPlot'
%It could be 'Set11', 'Set21','Set31' etc.
%How to make that work with dot notation ?
%Below is shown what I want, but it throws an error
plot(VarToPlot.Dures,VarToPlot.EMoteurTreuilAbar);
The error I get:
>> TestPlot
Unrecognized method, property, or field 'Dures' for class 'string'.
Error in TestPlot (line 24)
plot(VarToPlot.Dures,VarToPlot.EMoteurTreuilAbar);
1 个评论
"%In DataFile1 it is Set11, Set12 and Set13 %In DataFile2 it is Set21, Set22 and Set23 , etc"
And that is the start of your difficulties right there: putting meta-data (e.g. pseudo-indices, case numbers) into the variable names forces you into writing slower, more complex, less robust code.
In contrast if you used exactly the same variable names in each .mat file then your code would be simpler and more robust.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
