Hello!
My question would consist of both a static and a time-changing plot (animation).
Static part: (It will be closely related to the time-changing part)
My initial data types are:
xyz -> this is a matrix with rows containing the starting points of the vectors.
B -> this is a cell array containing the directions u, v, and w from the vectors' starting points in the form of a column vector.
C -> this contains the magnitude of each vector in turn.
For data, a brief example:
xyz = [1,0,0; 1,1,1; 1,0,1];
B = {[50,-2,5]; [23,-51,65]; [1,-6,-88]};
C = [52.29, 85.76, 88.21];
The task here would be to draw spatial arrows colored by their size.
I tried to use the following method to colour the vectors, but other methods might work as well:
RGB = [0 0 1
0 0.5 1
0 1 1
0 1 0.5
0 1 0
0.5 1 0
1 1 0
1 0.5 0
1 0 0 0];
colormap(RGB);
An important note for this exercise is that my input data is always in this format and I usually have to plot thousands of arrows like this.
Dynamic part:
Here you have to create an animation such that the matrix xyz is unchanged, but the matrix B and hence the matrix C calculated from it changes step by step.
At some point there are hundreds of steps in succession.
Thanks for your help!

2 comentarios

Image Analyst
Image Analyst el 27 de Mayo de 2025
That is not a method. It's just a colormap. C are your vector lengths, but what color goes with what length? Does each row in RGB correspond to a certain length? If so, which ones?
Mario
Mario el 27 de Mayo de 2025
The RGB matrix and a colormap is just an example, how I'd like to color the vectors based on ther magnitude.
It is just an idea but not an essential part. It okex with another coloring methods as well.

Iniciar sesión para comentar.

 Respuesta aceptada

Star Strider
Star Strider el 27 de Mayo de 2025

1 voto

The quiver3Dpatch File Exchange contribution can probably do what you want. You will need to use the usual quiver3 argument format for your data, instead of your current format.

4 comentarios

Mario
Mario el 27 de Mayo de 2025
Can you help me with the form and how I should convert my data to match the quiver3Dpatch function?
The lengths that you want are essentially the lengths of the vectors you posted, however greater precision would yield the exact values for the lengths that you posted.
I am not exactly certain how to convert your data to data that quiver3 wants, however the approach here may work.
Try this --
xyz = [1,0,0; 1,1,1; 1,0,1]
xyz = 3×3
1 0 0 1 1 1 1 0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
B = {[50,-2,5]; [23,-51,65]; [1,-6,-88]}
B = 3×1 cell array
{[ 50 -2 5]} {[23 -51 65]} {[ 1 -6 -88]}
C = [52.29, 85.76, 88.21]
C = 1×3
52.2900 85.7600 88.2100
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Bn = cell2mat(B)
Bn = 3×3
50 -2 5 23 -51 65 1 -6 -88
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
X = [xyz(:,1) Bn(:,1)]
X = 3×2
1 50 1 23 1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Y = [xyz(:,2) Bn(:,2)]
Y = 3×2
0 -2 1 -51 0 -6
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Z = [xyz(:,3) Bn(:,3)]
Z = 3×2
0 5 1 65 1 -88
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Len = sqrt(diff(X,[],2).^2 + diff(Y,[],2).^2 + diff(Z,[],2).^2)
Len = 3×1
49.2950 85.3464 89.2020
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
UVW = [ones(3,1) Len];
% UVW = gradient(Bn.')
U = [zeros(3,1) diff(X,[],2)];
V = [zeros(3,1) diff(Y,[],2)];
W = [zeros(3,1) diff(Z,[],2)];
figure
plot3(X.', Y.', Z.')
grid on
title('Vectors as ''plot3'' depicts them')
figure
quiver3(X.', Y.', Z.', U.', V.', W.')
grid on
title('Vectors as ''quiver3'' depicts them')
This is the best I can do with respect to reconstructing your data.
.:
Mario
Mario el 28 de Mayo de 2025
It works!
Thank yout! :)
Star Strider
Star Strider el 28 de Mayo de 2025
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Animation en Centro de ayuda y File Exchange.

Productos

Versión

R2025a

Preguntada:

el 27 de Mayo de 2025

Comentada:

el 28 de Mayo de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by