Azzera filtri
Azzera filtri

Plotting data within a loop

1 visualizzazione (ultimi 30 giorni)
Parveen Kumar
Parveen Kumar il 14 Feb 2019
Commentato: Parveen Kumar il 14 Feb 2019
Plotting data within a loop
I have a data in four columns
x, y, t, and ID
In this formar
1st column: X1,X2,X3,X4, X5, X6, X7, X8, X9…..Xn.
2nd column: Y1,Y2,Y3, Y4, Y5, Y7, Y8, Y9…..Yn
3rd is Time: 1,2,3,1,2,1,2,3,4,1,1…..n
4th ID: 1,1,1,2,2,3,3,3,3,4,5….
So whenever ID change the time start value. I want to plot each ID separately. For example: 1 track should be for ID=1, 2ndtrack for ID=2 and so on.
This is my code:
Tr is data file.
max1=max(tr(:,h)); %h column is ID column
for s=1:max1
for r=1:g
if tr(r,h)==s
scatter(tr(r,1),tr(r,2),5, 'filled','LineWidth',0.5)
hold on
end
end
end
This code has 2 problem. First too slow. 2nd I get scatter plot and each point is different color. I can not get tracks for each ID.
  2 Commenti
Parveen Kumar
Parveen Kumar il 14 Feb 2019
Is there any better way to sort and plot them with ID values. I mean one plot for each ID value.
Parveen Kumar
Parveen Kumar il 14 Feb 2019
Thank you for help and sharing imfornation.
Here is Data:
I want plot X,Y for as time progress (3rd) column for each value of ID (4th column). I want multiples lines for each valud of ID. Thankyou for your help.
X Y T ID
245.5854 142.0736 1 1
245.5854 142.0736 2 1
353.8233 2321.232 1 2
353.8233 2321.232 2 2
355.1186 2320.561 3 2
362.8682 3037.687 1 3
362.8682 3037.687 2 3
721.3332 3311.178 1 4
721.3332 3311.178 2 4
721.1143 3311.255 3 4
829.1324 702.0072 1 5
829.1324 702.0072 2 5
827.0101 700.621 3 5
1013.134 229.5366 1 6
1013.134 229.5366 2 6
1012.042 228.821 3 6
1242.613 1378.058 1 7
1242.613 1378.058 2 7
1242.325 1377.151 3 7
1905.737 1680.599 1 8
1905.737 1680.599 2 8
1942.877 1974.79 1 9
1942.877 1974.79 2 9
1941.808 1975.442 3 9
2236.604 665.5954 1 10
2236.604 665.5954 2 10
2235.779 667.1945 3 10
2292.883 1408.034 1 11
2292.883 1408.034 2 11
2712.549 1792.856 1 12
2712.549 1792.856 2 12
2711.623 1793.452 3 12
3340.355 335.6181 1 13
3340.355 335.6181 2 13
3442.762 569.0398 1 14
3442.762 569.0398 2 14
3441.822 569.8069 3 14
4074.356 1147.919 1 15
4074.356 1147.919 2 15
4118.562 2928.016 1 16
4118.562 2928.016 2 16
4151.829 1168.706 1 17
4151.829 1168.706 2 17
4187.846 3293.536 1 18
4187.846 3293.536 2 18
4186.573 3293.683 3 18
4241.491 3570.115 1 19
4241.491 3570.115 2 19
4315.192 639.7833 1 20
4315.192 639.7833 2 20
4313.016 640.6428 3 20
4356.717 3379.245 1 21
4356.717 3379.245 2 21
4354.655 3378.676 3 21
4588.88 949.6728 1 22
4588.88 949.6728 2 22
4588.115 950.4609 3 22
4815.942 2388.778 1 23
4815.942 2388.778 2 23
4815.923 2389.986 3 23

Accedi per commentare.

Risposta accettata

Bob Thompson
Bob Thompson il 14 Feb 2019
I'm not sure if I understand exactly what you're trying to do, but here goes.
nums = unique(tr(:,h));
for i = 1:length(nums)
figure(nums(i))
plot(tr(tr(:,h)==nums(i),x),tr(tr(:,h)==nums(i),time),tr(tr(:,h)==nums(i),y),tr(tr(:,h)==nums(i),time));
end
It's probably still going to be relatively slow because you're generating 23 different figures, and any graphical requirements take a fair amount of time in MATLAB.
  5 Commenti
Parveen Kumar
Parveen Kumar il 14 Feb 2019
Thank you so much. This works with some modications.
I was trying to plot X and Y for given condition on ID. I wanted all plots on one figure. Time is only for legend. Again Thank you very much.
This is what I did.
nums = unique(tr(:,h));
for i = 1:length(nums)
txt=['Track=', num2str(i)];
plot(tr(tr(:,h)==nums(i),1),tr(tr(:,h)==nums(i),2), 'LineWidth', 0.5,'DisplayName', txt);
hold on
title ('Particle Tracking');
xlabel ('X-(Pixel)')
ylabel ('Y-(Pixel)')
end
hold off
legend show
Parveen Kumar
Parveen Kumar il 14 Feb 2019
Thank you so much. This works with some modications.
I was trying to plot X and Y for given condition on ID. I wanted all plots on one figure. Time is only for legend. Again Thank you very much.
This is what I did.
nums = unique(tr(:,h));
for i = 1:length(nums)
txt=['Track=', num2str(i)];
plot(tr(tr(:,h)==nums(i),1),tr(tr(:,h)==nums(i),2), 'LineWidth', 0.5,'DisplayName', txt);
hold on
title ('Particle Tracking');
xlabel ('X-(Pixel)')
ylabel ('Y-(Pixel)')
end
hold off
legend show

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by