Plot Matrix in different colors of matrix depending on a different matrix
1 次查看(过去 30 天)
显示 更早的评论
Hellow,
I have made 4 vectors which I have combined to a long matrix of all combinations of the vectors:
Example: If A is a vector of 5 values, B is a vector of 3 values,C is a vector of 4 values and D is a vector of 5 values T1 is a matrix of 4 columns and 300 rows.
A=A';
B=B';
C=C';
D=D';
[C4,C3,C2,C1]=ndgrid(A,B,C,D);
T1=[C1(:) C2(:) C3(:) C4(:)];
Now I did this 2 times with different starting vectors(of the same number of values) so: E =5 rows, F =3 rows, G =4 rows, H =5 rows,
E=E';
F=F';
G=G';
H=H';
[D4,D3,D2,D1]=ndgrid(E,F,G,H);
T2=[C1(:) C2(:) C3(:) C4(:)];
After this I made some calculations with the T1 and T2 matrixes till they became 2 vectors of 1 column and in this case 300 rows called T and T'.
From T and T' I want too plot a point graphics. I did this:
hold on
box on
plot(T,T','rs','LineWidth',0.5)
xlabel('T')
ylabel('T'')
title('Energetische kostprijs efficientie')
hold off
So everything works till now. But now I would like to be able to let my graphics points be in a different colors depending on which values T1 and T2 matrices have. So lets say I want all points in my T, T' graphics in red which come from rows of witch T2 has in her first column a value between 1 and 2. All values witch come from a row in witch T2 has in her first column a value bigger than 2 in black and all values witch come from a row in witch T2 has in her first column a value smaller then 1 in blue.
I hope someone understand my explanation and has a solution to plot this.
Big thanks in advance!
0 个评论
回答(1 个)
dpb
2015-1-24
编辑:dpb
2015-1-25
plot returns a line object and the color is associated with the line, not the individual points. Hence, one must either plot lines selectively based on the values in order to set those line colors or, if it's only the points you're interested in coloring and not the lines as you've indicated in the question, then add a scatter call after you've plotted the line...
c=[0 0 1; 1 0 0; 0 0 0]; % blue, red black rgb color triplets
[~,ic]=histc(T2,[-inf 1 2 inf]); % bin indices by value
scatter(T,T.',40,c(ic,:),'filled')
See the doc's for details on scatter; the '40' is the size parameter.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!