0
votes

I have 3 vectors with values for coordinates (X,Y,Z) and I want to plot them as a surface. I have tried all sorts of solutions from here and other forums and cannot for the life of me get it to look like anything that makes sense. I have a picture that can describe the situation better but I can't post it as I don't have enough reputation. Please help. Thank you.

EDIT: This is the link to the picture : enter image description here

In the picture, the origin of each vector arrow represents the point in a 3D coordinate, with the length of the vector arrow giving the magnitude of the required torque to move at that point in 3D space.

Right now, the data is separated in line vectors with each point's coordinate: so that's one vector for the X, one for Y. Z is one line inside a 3 line matrix as the whole matrix describes the required torque in a 3 coordinate axes.

I've tried using meshgridon the X and Y vectors and then attributed the Z value using griddataand then surfbut I'm not getting something that looks like the original: enter image description here

The plot is linear but I'm pretty sure the data is not... at least not that linear.

3
If you can provide a link to the picture, somebody with more reputation can insert it in your question. - hbaderts
Can you tell us what would make sense for you? I can think of a couple of ways to plot 3D vectors - McMa
Show us some examples of how is your data defined. Are X,Y,Z matrices? Are they just points? do you expect a surface, vectors, lines? - Ander Biguri
drive.google.com/… . This one looks a bit more like the vector version (it's for another torque component) but the lines are all wrong. The problem is that the data generated is not uniform (one point next to the other) as the generator jumps from one coordinate to the other at the end of the map. Therefore, when the plot tries to link the points to create the surface, it creates a total mess. - Constantin Neacsu
sorry. all sorted now. the links can be viewed by anyone. - Constantin Neacsu

3 Answers

1
votes

It seems like you want want to plot the single points decribed by the vectors, here you have an old answer of mine (as a bonus you will have nice colorful plots 'cause that's what the original question asked):

Assuming Data=[Vec1,Vec2,Vec3,...] and VecN=[Xn,Yn,Zn]'

" If you want to plot points, you can define an RGB color and plot single points with hold on like this:

hold on

for i=1:length(Data(:,1)) 

    plot3(Data(i,1),Data(i,2),Data(i,3),'Color',[(i/100*255)/255 0/255 (255-(i/100*255))/255],'LineWidth',2)

end    

shg

"

1
votes

Managed to solve the problem. As mentioned, the data was not uniform and because of that, surfwas jumping from one end of the plot to the other, creating a total mess. Solved it by organising the values linearly using linspaceand then using those values to create the meshgrid and then assign the Z values using griddata with a cubic interpolation.. Managed to produce proper looking surface plots with the data on hand.

0
votes

Plot each data point separately within a loop:

figure; hold on; grid on;

for i = 1:length(x)
    stem3(x(i),y(i),z(i));
end

Don't forget to add hold on. Use "Rotate 3D" button from the toolbar in the figure window if the plot was shown in 2D at first.

enter image description here