Standard deviation: error because variable is of type double

6 ビュー (過去 30 日間)
Anna
Anna 2014 年 8 月 28 日
編集済み: yonatan gerufi 2014 年 8 月 28 日
I've created a 30 by 15 array of random numbers with mean M and standard deviation sd. I've then scaled the values from 0 to 1 because I want to show the matrix v using imshow, so I want the range to be from 0 to 1. Here is my code:
%create array of random numbers v = randn(30,15)*sd + M; %scale minimum = min(min(v)); maximum = max(max(v)); v = (v-minimum)/maximum;
I then want to find the new standard deviation and mean. To find the mean, I use:
Mean = mean(mean(V));
To find the standard deviation, I have used this code:
v = reshape(30*15, 1); standard_deviation = std(v);
Please tell me if there is a better way to get the standard deviation of ALL the numbers in a matrix, without reshaping to make it into a vector. When I use the above code, matlab throws an error: Undefined function 'sdt' for input arguments of type 'double'. Why is this? v is a vector so I can't see the problem with finding the standard deviation.
Thanks

採用された回答

yonatan gerufi
yonatan gerufi 2014 年 8 月 28 日
編集済み: yonatan gerufi 2014 年 8 月 28 日
Hi Anna,
you can use
std2(matrix)
mean2(matrix)
functions instead.
your code did work for me,
v = randn(30,15)*sd + M;
minimum = min(min(v));
maximum = max(max(v));
v = (v-minimum)/maximum;
Mean = mean(mean(v));
v = reshape(v,30*15, 1);
standard_deviation = std(v);
and that's it. good luck!

その他の回答 (2 件)

Adam
Adam 2014 年 8 月 28 日
std( v(:) )
works for any dimensionality of v

Image Analyst
Image Analyst 2014 年 8 月 28 日
To get the mean and sd
theMean = mean(v(:)); % Works always.
theMean = mean2(v); % Only if you have the Image Processing Toolbox
sd = std(v(:)); % Cast v to double if it's uint8 (like from an image).
To show the array, there is no need to scale to the range 0-1 , simple use []:
imshow(v, []); % Require the Image Processing Toolbox (which you say you have).

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by