Getting an unknown error on calculating Standard Deviation.

18 ビュー (過去 30 日間)
Amit Priyankar
Amit Priyankar 2020 年 6 月 19 日
コメント済み: Hassan Eissa 2023 年 9 月 8 日
I was trying to calculation using inbuilt Standard Deviation function but getting an error.
I ran the following code
load myfile.mat
std(v)
Error:
Error using var (line 74)
Invalid data type. First input argument must be single or double.
Error in std (line 59)
y = sqrt(var(varargin{:}));
  1 件のコメント
Atul Upadhyay
Atul Upadhyay 2020 年 6 月 19 日
I can see that the vector you are using has the int8 datatype in it and it contains values from 0 to 100. So, while calculating standard deviation there are chances of overflow.
Typecast the vector v to ‘double’ to get the desired output.
load myfile.mat;
v=double(v);
sd=std(v);
Refer to the following documentation to know more about datatypes in MATLAB.
https://in.mathworks.com/help/matlab/matlab_prog/integers.html

サインインしてコメントする。

採用された回答

Atul Upadhyay
Atul Upadhyay 2020 年 6 月 19 日
I can see that the vector you are using has the int8 datatype in it and it contains values from 0 to 100. So, while calculating standard deviation there are chances of overflow.
Typecast the vector v to ‘double’ to get the desired output.
load myfile.mat;
v=double(v);
sd=std(v);
Refer to the following documentation to know more about datatypes in MATLAB.
https://in.mathworks.com/help/matlab/matlab_prog/integers.html

その他の回答 (2 件)

Bjorn Gustavsson
Bjorn Gustavsson 2020 年 6 月 19 日
Your variable v is a uint8. Try:
std(double(v))
HTH

Hassan Eissa
Hassan Eissa 2023 年 9 月 8 日
Compute the maximum value (max), minimum value (min), average value (mean), standard deviation (std) and the variance ( square of the standard deviation) of the variable 'signal
  1 件のコメント
Hassan Eissa
Hassan Eissa 2023 年 9 月 8 日
[sample, signal]
Step 1 Compute the Statistics
This file contains a variable called signal that has 730 samples. Compute the maximum value (max), minimum value (min), average value (mean), standard deviation (std) and the variance ( square of the standard deviation) of the variable 'signal'.
% Create the variables below that represent the statistics of the variable signal
%
maxSignal =
minSignal =
avgSignal =
stdSignal =
varSignal =

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDigital Filter Analysis についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by