'Value' must be double scalar within the range of 'Limits'
3 次查看(过去 30 天)
显示 更早的评论
Hi. I am creating a gui on appdesigner. I am reading numeric data from a csv file and storing this data in an array. I want to calculate the standard deviation of the values store in the array and display it on the numeric edit field. The error I get is 'Value' must be a double scalar within the range of 'Limits'. But my Limit of the editfield is -Inf,Inf. The csv file is attached and the code is provided below. Please assist.
data=readtable('tests1.csv','NumHeaderLines',9);
col_vec=data{:,2}
app.stdEditField.Value=std(col_vec);
I tried editing the code to :
app.stdEditField.Value=std(single(col_vec))
Or
app.stdEditField.Value=std(double(col_vec))
But the error still pops up.
4 个评论
Adam Danz
2022-6-16
Please show us the results of data{:,2}, a few rows will be sufficient.
It may be helpful to see the results of std(col_vec) as well.
If col_vec is not a vector, then the result of std will not be a scalar. Table columns can contain matrices, for example.
Another possibility is that std is returning a NaN or Inf which may not pass the UI component validation.
采纳的回答
Adam Danz
2022-6-16
编辑:Adam Danz
2022-6-16
Your data contains a NaN value.
data=readtable('tests1.csv','NumHeaderLines',9);
col_vec=data{:,2};
n = sum(isnan(col_vec));
fprintf('There are %d NaN values in col_vec\n', n)
std(col_vec)
Where is the NaN value?
nanLoc = find(isnan(col_vec));
fprintf('NaN in row %d', nanLoc)
When there is at least 1 NaN in a vector, std will return NaN.
Options:
- Figure out why there are NaNs and replace them (manually, smoothing, interpolation, etc)
- Ignore the NaNs: S = std(___,nanflag)
sd = std(col_vec,'omitnan')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!