MATLAB Answers

Could someone tell me an easy way to plot graph when kk varies from 1 to 100?

조회 수: 6(최근 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
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;
hold on
hold on
hold on
Could someone tell me an easy way to plot graph when kk varies from 1 to 100?

  댓글 수: 0

로그인 to comment.

채택된 답변

Jakob B. Nielsen
Jakob B. Nielsen 15 Jan 2020
편집: Jakob B. Nielsen 15 Jan 2020
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.
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.
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 :)

  댓글 수: 5

표시 이전 댓글 수: 2
WalterWhite 15 Jan 2020
Thanks Jakob and moving the figure() outside the for loop may do parag

로그인 to comment.

추가 답변(1개)

CAM 15 Jan 2020
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).

  댓글 수: 1

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

Translated by