MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Ali Afshar Dodson
on 22 Aug 2014

Hi all,

I'm trying to plot an rgb matrix onto co-ordinates defined by Seed0Orange and Seed0Blue. However whilst the results work for i=1 when I try and cycle through the matrix I get "Error using plot Color value contains NaN, or element out of range 0.0 <= value <= 1.0". However there are no elements outside of the range or any NaNs. Any help would be much appreciated

for i = 1:5000 plot(Seed0Orange(1,i), Seed0Blue(1,i), 'kx','MarkerEdgeColor',[datanew(i,1) datanew(i,2) datanew(i,3)],... 'MarkerFaceColor',[datanew(i,1) datanew(i,2) datanew(i,3)]); end

*No products are associated with this question.*

Answer by Image Analyst
on 24 Aug 2014

(Regarding dpb's comment) You can find out which ones are above or below via the second return argument of min() or max(). Why not just clip

datanew(datanew>1)=1; datanew(datanew<0)=0;

before you enter the for loop and pass it into plot()?

I know I asked for your data before (above in the comments) but I haven't seen it yet, or any code as to how you created it. How was your colormap, datanew, generated?

## 7 Comments

## dpb

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/151953#comment_233129

Insufficient data, but...

What do

and

return?

## Adam

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/151953#comment_233137

Switch on the dbstop if error option (either in editor as I usually do from the Breakpoints menu or programmatically) and look at your

vector at the point it stops.

## Ali Afshar Dodson

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/151953#comment_233295

The min is 0.05, max is 1 and isnan = 0. The vector stops at [1, 0.5, 1] on the second iteration in.

## Image Analyst

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/151953#comment_233319

We'd probably need your data to help further.

## dpb

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/151953#comment_233322

About only other thought I'd have at this point would be floating point rounding...what do

return?

## Ali Afshar Dodson

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/151953#comment_233410

Looks like that might be the problem.

## dpb

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/151953#comment_233424

How was the array

datanewgenerated?If result of a floating point computation, it's always possible for the above to occur. To fix the issue can use several alternatives, probably the simplest is simply to clip the result on the upper bound by

To find which one(s) are the issue use

find-- perhaps there's a slight error in the computation or another reason for the problem that you want to correct other than by the above; can't tell that from here, of course.The second test above was intended to be <0 but that's not the case as I'd neglected that the previous result of

minwas shown to be 0.05. The result ofany<1is as expected of course, what would show the problem would beall<1which will show 0 1 0, the complement ofany>1.