when i try to run mean function

8 次查看(过去 30 天)
%load('Ftr.mat'); %load first 1000 data
data = xlsread('data.xlsx','Sheet1');
Ftrain= data(1:990, :);
Ftest=data(991:1000, :);
X=Ftrain;
[n,p] = size(X); %n = number of observations/samples
%mean
c=mean(X);
mu=repmat(c,n,1);
%standard deviation
d=std(X);
%Upper control limimt
UCL=c+3*d;
x=repmat(UCL,n,1);
%Lower control limimt
LCL=c-3*d;
y=repmat(LCL,n,1);
P=1:n;
it shows error.
Error using sum
Invalid data type. First argument must be numeric or logical.
Error in mean (line 127)
y = sum(x, dim, flag) ./ mysize(x,dim);
Error in XbarRS3DC (line 8)
c=mean(X);

回答(1 个)

Walter Roberson
Walter Roberson 2020-12-1
No, that error literally cannot happen with the code you posted.
In your previous question, you posted an error that can only occur if Data is datatype table(), which was not possible when using xlsread(). We can predict that your current problem involves the same thing, that somehow Data is datatype table() even though that is not a possibility when you use xlsread() .
That problem can occur if you use readtable() instead of xlsread().
If you were using readtable() then you would need to pick out numeric columns, and ask to extract the numeric content. For example,
X = Ftrain{:, 1:3};

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by