0

I have some color matrices like below and originally, there is only one color matrix and it works well.

[66 92 143]/255; %DARKBLUE 
[21 59 99]/255; %BLACK
[0 0 0]; %Pure black

tempPoint.set('mark_color',{[21 59 99]/255});

I have tried to put these color matrices into a vector.So I can use it in a loop like this:

farbe=[[21 59 99]/255 [0 0 0] [66 92 143]/255];

 for i=1:length(farbe) 

tempPoint.set('mark_color',{farbe(i)}); 

end

But unfortunately it doesn't work and it gives an "Color value must be a 3 element numeric vector" error

I tried to find a solution to my problem at this topic but couldn't make it work for mine:

Array of Matrices in MATLAB

How can I put these matrices into a vector and use its every element in a loop ?

Any help will be appreciated.

1
  • 1
    place them into a cell matrix farbe ={[21 59 99]/255, [0 0 0], [66 92 143]/255} Then call them with farbe{i} Be careful to use } not ) when calling them. Commented Jun 6, 2014 at 12:48

2 Answers 2

1

Your Problem is: your new farbe has size 9. therefor in your loop you are calling it with only 1 input instead of 3. Either change your parameter in farbe or change the datatype. Here 2 solutions:
1 solution: Using cell:

%I changed farbe to be a cell array with each element containing 1 colour
farbe={[21 59 99]/255, [0 0 0], [66 92 143]/255};

 for i=1:length(farbe) 
  %Here the call farbe changed (using {} instead of() to get the values)
  tempPoint.set('mark_color',{farbe{i}}); 

end

2nd solution:other looping

farbe=[[21 59 99]/255 [0 0 0] [66 92 143]/255];

 for i=1:length(farbe)/3 

tempPoint.set('mark_color',{farbe(3*i-2:3*i)}); 

end

Here the diferent parameter is to make sure that you use right indexing. You could also change your loop parameter to i=1:3:7and use farbe(i:i+2)

Also as an annotation you shouldn't use i as parameter since it is also the MATLAB intern variable for imaginary units. same as j. Use either ii and jj or something else.

Also i wasn't able to test my solutions since i don't have a temp.Point.set method. So feedback would be appreciated.

Sign up to request clarification or add additional context in comments.

Comments

1

You can do this in two ways either by making farbe into a matrix like this:

farbe=[[21 ;59 ;99]/255 [0 ;0 ;0] [66; 92 ;143]/255]

and then

for i=1:length(farbe) 

tempPoint.set('mark_color',{farbe(:,i)}); 

end

or make them as a cell by:

farbe=[{[21 59 99]/255} {[0 0 0]} {[66 92 143]/255}];

for i=1:length(farbe) 

tempPoint.set('mark_color',{farbe{i}}); 

end

1 Comment

Your first solution shouldn't work. When I am not mistaken your call farbe(i)still returns only one value. You would have to change it to farbe(:,i)for it to use the "whole" colormapping.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.