Drawing line segments in a 3d plot

27 visualizzazioni (ultimi 30 giorni)
Harry il 12 Lug 2020
Risposto: jonas il 12 Lug 2020
Hi, given a matrix, such as
rand(6,5)
I want to create a 3d plot containing line segmentes, where each line segment is purple, begins at a blue point, with the x, y, z co ordinates taken from the entries in the 1st, 2nd and 5th columns of the matrix, and ends at a red point with the x, y, z co ordinates taken from the entries in the 3rd, 4th and 5th columns of the matrix.
0 CommentiMostra -1 commenti meno recentiNascondi -1 commenti meno recenti

Accedi per commentare.

Risposta accettata

jonas il 12 Lug 2020
Something like this?
A = rand(6,5);
startv = [A(:,1),A(:,2),A(:,5)];
endv = [A(:,3),A(:,4),A(:,5)];
figure;hold on
scatter3(startv(:,1),startv(:,2),startv(:,3),[],'b','filled');
scatter3(endv(:,1),endv(:,2),endv(:,3),[],'r','filled');
h = plot3([startv(:,1)';endv(:,1)'],...
[startv(:,2)';endv(:,2)'],...
[startv(:,3)';endv(:,3)'])
set(h,'color',[128,0,128]./255);
view(3)
0 CommentiMostra -1 commenti meno recentiNascondi -1 commenti meno recenti

Accedi per commentare.

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by