error in std for 3d matrix

조회 수: 3 (최근 30일)
Anastasia
Anastasia 2016년 12월 12일
댓글: Guillaume 2016년 12월 13일
Hey guys!
I am trying to find the std of a 3D matrix, where size(X) is 207 x 201 x 34. Since I must reshape to find std, I am using this formula: std(reshape(X,1,207*201*34)).
And I obtain this error: Error in std (line 31) y = sqrt(var(varargin{:}));
When I look at the syntax, I thought of using std(reshape(X,1,207*201*34), 0, 3), where 3 is for 3D, however I still obtain the same error.
What I am missing?
Thank you very much in advance!
  댓글 수: 2
Steven Lord
Steven Lord 2016년 12월 12일
What is the full text of the error message (including everything printed in red?)
Anastasia
Anastasia 2016년 12월 13일
편집: Anastasia 2016년 12월 13일
Hello, this is the full text of the error message:
Error using var (line 58) First argument must be single or double.
Error in std (line 31) y = sqrt(var(varargin{:}));
Error in Code3D (line 27) th=mean(mean(mean(X))) + std(reshape(X,1,207*201*34));
Is the problem that X is nor single nor double, but 207*201*34? How can I fix that?
Thank you!

댓글을 달려면 로그인하십시오.

답변 (2개)

Isabella Osetinsky-Tzidaki
Isabella Osetinsky-Tzidaki 2016년 12월 12일
try std(x(:))
  댓글 수: 1
Anastasia
Anastasia 2016년 12월 13일
Hello! Thank you for your answer but I obtain the same error...

댓글을 달려면 로그인하십시오.


Guillaume
Guillaume 2016년 12월 13일
Error: First argument must be single or double
Well, clearly, your first argument (a transform of X) is not single or double. So what is:
class(X)
If it's an integer type:
Xdouble = double(X);
th = mean(Xdouble(:)) + std(Xdouble(:));
  댓글 수: 2
Anastasia
Anastasia 2016년 12월 13일
The class is uint16. I tried it and it works, is it correct to use the code you gave me with a uint16 class?
Thanks!
Guillaume
Guillaume 2016년 12월 13일
Without context it's impossible to say if it's correct or not. Certainly, if you want the standard deviation of your integers, you have to convert them to double. If an integer result is then required, you can convert the output back to uint16 (with the loss of precision that it entails).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by