Could someone tell me an easy way to plot graph when kk varies from 1 to 100?
4 次查看(过去 30 天)
显示 更早的评论
I run the function file
for kk = 1:4
and saved by using
save(['A', num2str(kk),'.mat']) command and then I plot the graphs as follow
clear
clc
A1 = load('A1.mat');
A2 = load('A2.mat');
A3 = load('A3.mat');
A4 = load('A4.mat');
DAT1 = A1.var_emg_value';
DAT2 = A2.var_emg_value';
DAT3 = A3.var_emg_value';
DAT4 = A4.var_emg_value';
x = A1.Bvalues;
figure()
plot(x,DAT1,'r');
hold on
plot(x,DAT2,'c');
hold on
plot(x,DAT3,'g');
hold on
plot(x,DAT4,'k');
Could someone tell me an easy way to plot graph when kk varies from 1 to 100?
0 个评论
采纳的回答
Jakob B. Nielsen
2020-1-15
编辑:Jakob B. Nielsen
2020-1-15
Do you need all the variables open with every information in the workspace after the plotting? If not, I would do something like this. (Note you dont need to hold on after every plot. When you set hold on, hold is on until you tell it to be off.
A1 = load('A1.mat');
x=A1.Bvalues; %am I correct in assuming your x is the same for every run? Otherwise you must define it within the loop
hold on
for j=1:100
runningfilename=strcat('A',num2str(j),'.mat'); %this should give you 'A1.mat' first run, 'A2.mat' 2nd run, etc.
data=load(runningfilename);
yplot=ata.var_emg_value; %if you dont need any matrix/table with data, just the plots.
%%%% OR
%yplot(:,j)=data.var_emg_value; %you will end up with a yplot matrix of dimension ?x100
%and finally plotting:
plot(x,yplot); %OR plot(x,yplot(:,j)); if you go with the matrix option.
end
Try this - it should produce 100 plots in the same window (notice how hold on is only called once). You can do all sorts of clever things with indexing and for loops, once you know how :)
更多回答(1 个)
CAM
2020-1-15
Have you considered putting all emg data columns in a cell array, with the first cell containing the x-values? That way you only have to save one mat-file.
If you want to keep the separate files, you could use a loop to build the cell array as you read each file (and add to the plot).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!