2012-03-06 191 views
4

我有一個矩陣的單值類型,我想繪製爲曲面。當我嘗試使用MATLAB中的衝浪功能,我得到一個錯誤,指定我需要使用UINT8或翻番,而不是:爲什麼MATLAB surf功能不能處理單精度數據?

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

現在,我會盡力單打:

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

提供了以下錯誤:

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

那麼這是不幸的。我想我必須增加到雙精度的色圖:

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

工作得很好。但只是踢,讓我們嘗試UINT8還有:

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

產生如下:

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 

什麼鬼MATLAB?下定決心!那麼,爲什麼我必須以雙精度的形式使用額外的內存來表示surf函數的顏色映射?即使當MATLAB錯誤文本告訴我,我可以使用uint8 單,取決於哪一個我沒有使用

回答

1

愛這個問題。

不知道你是否看到了this,但它至少能解決你同樣的厭惡。聽起來像邁克爾對uint8算法的性能感到失望,因爲他描述了它似乎爲自己創造了更多的計算工作,而且不符合他的審美需求。我與peaks樣品試了一下,這就是我得到:

Raw Peaks Data

然後我說一個偏移量來獲取所有的情節。

Offset Peaks Data

嗯,這很好,我猜。這裏的代碼,希望這是有用的。

% 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') 
+0

這是一個有趣的解決方案,但並不真正適合我的問題。我需要更多的色彩分辨率。我想我只是想用'surf(x,double(x))'這個解決方案。 – Doresoom 2012-03-07 15:38:12