when i try to run mean function

8 views (last 30 days)
Logeswaran pitchai muthaiyah
Answered: Walter Roberson on 1 Dec 2020
%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);

Answers (1)

Walter Roberson
Walter Roberson on 1 Dec 2020
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};

Tags

Community Treasure Hunt

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

Start Hunting!