필터 지우기
필터 지우기

plotting mutiple curve in the same graph

조회 수: 7 (최근 30일)
Chun Fai Leung
Chun Fai Leung 2022년 7월 16일
댓글: Star Strider 2022년 7월 29일
I would like to plot a graph for the table. So I use the following code.
clear
dataset = xlsread('modifiedDataset.xlsx','Sheet1');
x = dataset(:,6);
y = dataset(:,11);
plot(x,y);
But for column G, the number are actually the particle numbers. I would like to plot several curve in the same graph if possible, each curve for each particle respectively. In this case, there are 9 particles. Is there any code that could help me identify the particle number and plot the curves respectively. I'm new to MATLAB, sorry about that. I would much appreciate your help. Thank you.

채택된 답변

Star Strider
Star Strider 2022년 7월 16일
Here are two options —
dataset = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1067780/modifiedDataset.xlsx');
x = dataset(:,6);
y = dataset(:,11);
p = dataset(:,7);
up = unique(p);
figure
hold on
for k = 1:numel(up)
Lv = p == up(k);
plot(x(Lv), y(Lv), 'DisplayName',sprintf('Particle %d',up(k)))
end
hold off
grid
legend('Location','best')
NrSP = numel(up);
figure
hold on
for k = 1:numel(up)
subplot(5,2,k)
Lv = p == up(k);
plot(x(Lv), y(Lv))
grid
ylim([0 1.4])
title(sprintf('Particle %d',up(k)))
end
hold off
There are other possibilities as well.
.
  댓글 수: 12
Chun Fai Leung
Chun Fai Leung 2022년 7월 29일
wow sir. It looks so much better and exactly what I want. I do want to exclude the extreme values and delete the rows of data, apparently you have also done it already.So when I redo the experiment again with different light intensity, should I always check for extreme values and exclude them again. Thank you so much sir.
Star Strider
Star Strider 2022년 7월 29일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by