Creating seperate lines using plot3()

Hi, the issue might be simple but I'm still stuck with it. The goal is to create a 3D plot with separate lines using plot3(). A new line is supposed to start each time the whole row is NaN.
I created a normal array 'coast3'. lat and long are column arrays:
r = 6371;
x = r.*cos(lat).*cos(long);
y = r.*cos(lat).*sin(long);
z = r.*sin(lat);
coast3 = [x,y,z]
The command plot3(x,y,z) produces just one single line. There's 240 rows that are NaN. So I produced a cell array 'D':
idx = all(isnan(coast3),2);
idr = diff(find([1;diff(idx);1]));
D = mat2cell(coast3,idr(:),size(coast3,2))
It seems like the cell array can't be plotted with plot3. At least I don't see a way.
Would be so great if anyone knows a way to plot that.
Cheers and thanks!

2 commentaires

Adam Danz
Adam Danz le 10 Mai 2021
Hello @Luca Koldeweyh welcome to the forum. I formatted your code so it's easier to read and more enticing to answer. In the future you can format code in the forum using the Text/Code toggle button in the rich text editor (instructions).
Adam Danz
Adam Danz le 10 Mai 2021
From the plot3 documentation,
"To plot multiple sets of coordinates on the same set of axes, specify at least one of X, Y, or Z as a matrix and the others as vectors." ... "Each of X, Y, and Z must have at least one dimension that is same size". (Examples provided in the link).
If you provide more info about where the NaNs come come or, better yet, attach a mat file containing the lat and long variables, perhaps I could give more specific guidance.

Connectez-vous pour commenter.

Réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by