Effacer les filtres
Effacer les filtres

Matlab plot3 line color setting

79 vues (au cours des 30 derniers jours)
Mohsin Khan
Mohsin Khan le 14 Fév 2022
Modifié(e) : Mohsin Khan le 17 Fév 2022
I want to plot a three-dimensional line chart using the plot3 function in matlab. The following code works to plot the lines with specified colour names 'r','g','k', etc. However,Iit gives an error when I replace the first colour by 'myGreen' using the RGB triplet: 'Error using plot3 Vectors must be the same length.'
How can I resolve this issue?
[xx,zz]=meshgrid(1:230,1:4);
x1=(xx(1,:));
x2=(xx(2,:));
x3=(xx(3,:));
x4=(xx(4,:));
z1=(zz(1,:));
z2=(zz(2,:));
z3=(zz(3,:));
z4=(zz(4,:));
yy=rand(230,4);
y1=(yy(:,1));
y2=(yy(:,2));
y3=(yy(:,3));
y4=(yy(:,4));
% custom colour
myGreen=[0 0.5 0];
index={'data1','data2','data3','data4'}
figure
% It works and produces the attached figure
plot3(x1',z1',y1','r',x2',z2',y2','m', x3',z3',y3','b',x4',z4',y4','k')
% It doesn't work
plot3(x1',z1',y1','Color',myGreen,x2',z2',y2','m', x3',z3',y3','b',x4',z4',y4','k')
set(gca,'YTick',1:4,'YTickLabel',index)
grid on
xlabel('xlabel','FontSize',10);
zlabel('zlabel','FontSize',10)
axis tight

Réponses (1)

Yongjian Feng
Yongjian Feng le 14 Fév 2022
Separate them:
plot3(x1',z1',y1','Color', myGreen);
hold on
plot3(x2',z2',y2', 'm', x3',z3',y3','b', x4',z4',y4','k');

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by