Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Surf Plot - Contradictory Data Type Errors

Subject: Surf Plot - Contradictory Data Type Errors

From: Michael

Date: 13 Apr, 2010 21:41:04

Message: 1 of 3

I have encountered contradictory errors while trying to perform a surf plot on non-double datatypes. Example code:

>> a=256*rand(5);
>> b=uint8(a); surf(b)
Warning: CData must be double or single unless it is used only as a texture data
Warning: CData must be double or single unless it is used only as a texture data
>> c=single(a); surf(c)
Warning: CData must be double or uint8.
Warning: CData must be double or uint8.
>> d=double(a); surf(d) % no errors on this command, surf(d) works fine
>>

So, given a 5x5 array in various data formats, MATLAB does the following:

1) Claims it can't surf plot a uint8 array because it requires either single or double
2) Claims it can't surf plot a single array because it requires either uint8 or double
3) Plots double format just fine, as expected

Does anyone have any insight into this? My main questions are:

Q1) Why the contradictory errors between the attempt at surf plotting a uint8 array vs. a single array?
Q2) Is there a way to surf plot a data format with less memory footprint than required for double arrays?

FYI, my application is video image processing with tens of thousands of frames. The data is all uint16 and I'd like to be able to work with less memory overhead.

Thanks,
Mike

Subject: Surf Plot - Contradictory Data Type Errors

From: Wayne King

Date: 14 Apr, 2010 10:58:04

Message: 2 of 3

"Michael " <mcdon06@umich.edu> wrote in message <hq2odg$k3o$1@fred.mathworks.com>...
> I have encountered contradictory errors while trying to perform a surf plot on non-double datatypes. Example code:
>
> >> a=256*rand(5);
> >> b=uint8(a); surf(b)
> Warning: CData must be double or single unless it is used only as a texture data
> Warning: CData must be double or single unless it is used only as a texture data
> >> c=single(a); surf(c)
> Warning: CData must be double or uint8.
> Warning: CData must be double or uint8.
> >> d=double(a); surf(d) % no errors on this command, surf(d) works fine
> >>
>
> So, given a 5x5 array in various data formats, MATLAB does the following:
>
> 1) Claims it can't surf plot a uint8 array because it requires either single or double
> 2) Claims it can't surf plot a single array because it requires either uint8 or double
> 3) Plots double format just fine, as expected
>
> Does anyone have any insight into this? My main questions are:
>
> Q1) Why the contradictory errors between the attempt at surf plotting a uint8 array vs. a single array?
> Q2) Is there a way to surf plot a data format with less memory footprint than required for double arrays?
>
> FYI, my application is video image processing with tens of thousands of frames. The data is all uint16 and I'd like to be able to work with less memory overhead.
>
> Thanks,
> Mike

Hi Mike,

a=256*rand(5);
b=uint8(a);
surf(b,'facecolor','texturemap')

Wayne

Subject: Surf Plot - Contradictory Data Type Errors

From: Michael

Date: 14 Apr, 2010 14:04:04

Message: 3 of 3

"Wayne King" <wmkingty@gmail.com> wrote in message <hq473s$i4v$1@fred.mathworks.com>...
>
> Hi Mike,
>
> a=256*rand(5);
> b=uint8(a);
> surf(b,'facecolor','texturemap')
>
> Wayne

Hi Wayne,

  Thanks for your reply, I tried it and like the mapping idea but the results are not ideal. I think it could work with tweaking, but I'm not sure if any tweaking is possible.

  If you look at the way the 2D texture map onto the 3D surface works, the int array "b" is used to create a 5x5 grid of colors. But if you run a surf plot of the 5x5 double array "a", you see that there are really only 4x4 faces, because in general an NxN grid of points only forms an N-1xN-1 grid of cells or squares.

>> a=256*rand(5);
>> b=uint8(a);
>> subplot(1,2,1)
>> surf(a)
>> subplot(1,2,2)
>> surf(b,'facecolor','texturemap')

  You end up with an effect where MATLAB tries to lay a 5x5 quilt of colors over a 4x4 surface plot -- the vertices don't match up and it's not very nice.

  So, do you know of a way to fix that overlap flaw? I imagine you could do bilinear interpolation on the original grid to get a N-1xN-1 array of values at the center of the cells, but I don't know that you could feed in one array to plot with another for the texture map data. Besides, the extra computation would defeat the purpose of the simplicity and speed I was going for.
  

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us