Why doesn't MATLAB surf function work with single precision data?

I have a single value matrix that I want to build as a surface. When I try to use the surf function in MATLAB, I get an error indicating that I need to use uint8 or double instead:

x=peaks; %# Initialize x to a matrix of doubles surf(x); %# No problem when x is of type double 

Now I will try the singles:

 x=single(peaks); surf(x); 

Gives the following error:

 Warning: CData must be double or uint8. Warning: CData must be double or uint8. 

Well, this is unfortunate. I think I will have to double the precision for the color map:

 x=single(peaks); surf(x,double(x)); 

It works well. But just for beats, also try uint8:

 x=single(peaks); surf(x,uint8(x)); 

The following are allowed:

 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 

What the hell MATLAB? Make up your mind! So, why should I use additional double precision memory to indicate the color scheme for the surf function? Even when the MATLAB error text tells me that I can use uint8 or single, depending on which I did not use ?

+4
source share
1 answer

Love the question.

Not sure if you saw this or not, but at least it concerns your own disgust. Michael seems to have given up on performance in the uint8 algorithm, in which he describes how he seems to be creating more computing work for himself with a plot that does not meet his aesthetic needs. I tried it with a peaks sample, and this is what I get:

Raw peaks data

Then I added an offset to get the whole graph.

Offset Peaks Data

Eh, that's fine, I think. Here's the code, hopefully this was helpful.

 % Test code from Matlab Central a=256*rand(5); b=uint8(a); figure; surf(b,'facecolor','texturemap') % get the example peaks data % and plot without any scaling x = peaks; figure; surf(uint8(x),'facecolor','texturemap') % get the offset to keep all the data positive % not pretty but functional xp = x-min(min(x))+1; figure; surf(uint8(xp),'facecolor','texturemap') 
+1
source

Source: https://habr.com/ru/post/1400115/


All Articles