Filter löschen
Filter löschen

plotting mutiple curve in the same graph

7 Ansichten (letzte 30 Tage)
Chun Fai Leung
Chun Fai Leung am 16 Jul. 2022
Kommentiert: Star Strider am 29 Jul. 2022
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.

Akzeptierte Antwort

Star Strider
Star Strider am 16 Jul. 2022
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 Kommentare
Chun Fai Leung
Chun Fai Leung am 29 Jul. 2022
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 am 29 Jul. 2022
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by