Plot Label, Tile and Legend at the same time of the live plot

13 ビュー (過去 30 日間)
Fabio Taccaliti
Fabio Taccaliti 2022 年 6 月 22 日
編集済み: Cris LaPierre 2022 年 6 月 23 日
I have a live scatter 3D plot that plots a two sets of scatter together.
Right now with this code the label, legend and title are just showing at the end.
How can I plot these all together with the scatter and not just at the end?
Please note that the scatter are plotting just a datset of the cell for each time instant, without showing the previous one, I would like to keep it.
I tried several combinations of hold on and hold off but I didn't manage to do it.
figure;
for i=1:numel(Coordinates(:,1))
view(3)
set(gcf, 'Color', 'White');
set(gca, 'Fontsize', 12);
scatter3(DD{i}(:,2),DD{i}(:,3),DD{i}(:,4), 'b', 'filled')
hold on;
scatter3(Coordinates{i,1},Coordinates{i,2},Coordinates{i,3}, 'k', 'filled')
hold off;
grid on; grid minor;
axis equal;
set(gca, 'ZDir','reverse');
drawnow;
pause(0.001);
xlabel('x [mm]')
ylabel('y [mm]')
zlabel('z [mm]')
legend('STB','7DOF Fit')
title(['Time = ', num2str(round(DD{i}(1,1),2)), ' s'])
end
Please let me know.

採用された回答

Cris LaPierre
Cris LaPierre 2022 年 6 月 22 日
I would rearrange your code to set everythign up before entering the for loop, and then in the loop, just update the plot data. It might look something like this (untested)
figure;
figure;
s1 = scatter3(nan,nan,nan, 'b', 'filled');
hold on;
s2 = scatter3(nan,nan,nan, 'k', 'filled');
hold off;
xlabel('x [mm]')
ylabel('y [mm]')
zlabel('z [mm]')
legend('STB','7DOF Fit')
view(3)
set(gcf, 'Color', 'White');
set(gca, 'Fontsize', 12);
grid on; grid minor;
axis equal;
set(gca, 'ZDir','reverse');
for i=1:numel(Coordinates(:,1))
title(['Time = ', num2str(round(DD{i}(1,1),2)), ' s'])
s1.XData = DD{i}(:,2);
s1.YData = DD{i}(:,3);
s1.ZData = DD{i}(:,4);
s2.XData = Coordinates{i,1};
s2.YData = Coordinates{i,2};
s2.ZData = Coordinates{i,3};
drawnow;
pause(0.001);
end
  4 件のコメント
Cris LaPierre
Cris LaPierre 2022 年 6 月 23 日
編集済み: Cris LaPierre 2022 年 6 月 23 日
The error appears to be with Coordinates, specifically that Coordinates{i,1} does not return a vector. What are the contents of each cell? You may have to decide what makes the most sense here as you are most familiar with your data. One possible solution is to turn the result into a vector using this syntax
s2.XData = Coordinates{i,1}(:);
Fabio Taccaliti
Fabio Taccaliti 2022 年 6 月 23 日
Yesss, now is working! Thanks Cris :)
Coordinates was 102x3 cell with each 14x4 double.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by