when i try to run mean function

조회 수: 6 (최근 30일)
Logeswaran pitchai muthaiyah
Logeswaran pitchai muthaiyah 2020년 12월 1일
답변: Walter Roberson 2020년 12월 1일
%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
Image Analyst
Image Analyst 2020년 12월 1일
Can you attach 'data.xlsx'?

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

답변 (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에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by