How to give different colors to different tracts?

1 visualización (últimos 30 días)
Gustavo
Gustavo el 21 de Jun. de 2013
Hi.
I have some tracts and i can plot them using plot3. I would like to give to each tract a color, using some information about the relative distance between the first and last point of that tract.
For example: Tract1 goes from (1,1,1) to (6,8,12). So: Diff is (5,7,11).
I know that RGB codes are something like [1 0 0] or [1 0.4 0.6]. With this i made [(Diff(1)/(Diff(1)+Diff(2)+Diff(3)) (Diff(2)...) (Diff(3)...)] but it gives me this error: 'Error in color/linetype argument'.
How can i solve this?
Thanks in advance
  3 comentarios
the cyclist
the cyclist el 3 de Jul. de 2013
You could put this as an answer (rather than a comment), and accept it.
Jan
Jan el 4 de Jul. de 2013
j=1:size(TRACTS{i}) is at least confusing: size() replies a vector and what do you expect as output of: 1:[22,23]? So better define the wanted dimension in the size() command.
There is no reason to clear 'V'. A pre-allocation would be much more important instead:
V = zeros(size(TRACTS{i}, 1), 3);

Iniciar sesión para comentar.

Respuesta aceptada

Gustavo
Gustavo el 5 de Jul. de 2013
By sugestion of the cyclist:
I found it. If anyone needs it there it is:
function []= Test (TRACTS%%Cell with structs within, INFO%Information about each tract)
close all;
for i=1:INFO.n_count
clear V;
for j=1:size(TRACTS{i})
G(j) = TRACTS{i}(j,1); %Info about x axis
H(j) = TRACTS{i}(j,2); %Info about y axis
I(j) = TRACTS{i}(j,3); %Info about z axis
J = G(j)-G(1);
K = H(j)-H(1);
L = I(j)-I(1);
V(j,1)=J;
V(j,2)=K;
V(j,3)=L;
W(i,j) = abs(V(j,1))+abs(V(j,2))+abs(V(j,3));
end
%knowing that RGB color codes are [a b c]
%we consider the weight that each V has in the W
%obtaining something like [0.1 0.2 0.6]
M = [abs(V(j,1))/W(i,j) abs(V(j,2))/W(i,j) abs(V(j,3))/W(i,j)];
plot3(TRACTS{i}(:,1),TRACTS{i}(:,2),TRACTS{i}(:,3),'Color',M);grid on;
hold on;
end
end
I am not sure of what you pretended Jan Simon. I need to change the number of iterations for each position of the cell TRACTS, because the number of points used to generate a track differs. I made this code and he works reasonibly well. However i am open to any changes that you or anyone sugest in order to enhance this code :)

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by