Matlab plot3 line color setting

26 ビュー (過去 30 日間)
Mohsin Khan
Mohsin Khan 2022 年 2 月 14 日
編集済み: Mohsin Khan 2022 年 2 月 17 日
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

回答 (1 件)

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

カテゴリ

Help Center および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by