plotting mutiple curve in the same graph

16 vues (au cours des 30 derniers jours)
Chun Fai Leung
Chun Fai Leung le 16 Juil 2022
Commenté : Star Strider le 29 Juil 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.

Réponse acceptée

Star Strider
Star Strider le 16 Juil 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 commentaires
Chun Fai Leung
Chun Fai Leung le 29 Juil 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 le 29 Juil 2022
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by