Error using mean: Too many input arguments.

Dear MATLAB experts,
I keep on getting the error described in the title of the question and I don't know how to solve it. The implemented code is the one you find below.
stock_priceStats = table();
stock_priceStatsVars = stockprice_data.Properties.VariableNames;
for i = 1:width(stockprice_data)
colData = stockprice_data.(i);
stock_priceStats.(i) = mean(colData{:});
stock_priceStats.(i) = std(colData{:});
stock_priceStats.(i) = min(colData{:});
stock_priceStats.(i) = quantile(colData{:}, .25);
stock_priceStats.(i) = median(colData{:});
stock_priceStats.(i) = quantile(colData{:}, .75);
stock_priceStats.(i) = max(colData{:});
end
stock_priceStats.Properties.Variablenames = stock_priceStatsVars;
After also typing in the command window:
which -all mean
I get the following:
/Applications/MATLAB_R2021a.app/toolbox/matlab/datafun/mean.m
/Applications/MATLAB_R2021a.app/toolbox/matlab/datatypes/duration/@duration/mean.m % duration method
/Applications/MATLAB_R2021a.app/toolbox/matlab/datatypes/datetime/@datetime/mean.m % datetime method
/Applications/MATLAB_R2021a.app/toolbox/matlab/bigdata/@tall/mean.m % tall method
/Applications/MATLAB_R2021a.app/toolbox/matlab/timeseries/@timeseries/mean.m % timeseries method
/Applications/MATLAB_R2021a.app/toolbox/nnet/deep/@dlarray/mean.m % dlarray method
I would be really grateful if you could help me out with this.
Thank you in advance.

댓글 수: 3

Thank you, this works! But now I get the following error for
stock_priceStats.(i) = quantile(colData{:}, .25);
Not enough input arguments.
Error in quantile (line 51)
if ~isvector(p) || isempty(p).
I have implemented your suggestion in all the code lines above.
The actual problem is that you are generating a comma-separated list and supplying multiple inputs to MEAN:
mean(colData{:})
% ^^^ comma-separated list
What do you expect that to achieve?
DGM
DGM 2021년 9월 29일
Can you provide an example of stockprice_data so that I can replicate the issue?

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

 채택된 답변

DGM
DGM 2021년 9월 29일
편집: DGM 2021년 9월 29일

0 개 추천

I'm not sure how these arrays are shaped or what the contents are, but I'm guessing you can do something like this:
mean(vertcat(colData{:}))
to collect the multiple outputs of coldata{:} into a single vector.
If that's the case, it would be more efficient to avoid replicating the operation:
stock_priceStats = table();
stock_priceStatsVars = stockprice_data.Properties.VariableNames;
for i = 1:width(stockprice_data)
colData = stockprice_data.(i);
colData = vertcat(colData{:});
% alternatively, you may simply be able to do it in one line
stock_priceStats.(i) = mean(colData);
stock_priceStats.(i) = std(colData);
stock_priceStats.(i) = min(colData);
stock_priceStats.(i) = quantile(colData, .25);
stock_priceStats.(i) = median(colData);
stock_priceStats.(i) = quantile(colData, .75);
stock_priceStats.(i) = max(colData);
end

댓글 수: 3

chiefjia
chiefjia 2021년 9월 29일
편집: chiefjia 2021년 9월 29일
Thank you for your input DGM!
Now the issue that I encounter is that each one of the values (mean, std, min, quantile(.25), median, quantile (.75) and max) should be displayed in a different row for each one of the columns of stock_priceStats, as the output of this forloop is one row for every single row of stock_priceStats.
How could I display these different informations on different rows for each variable/column?
find the data on stockprice_data in this link: stockprice_data
Maybe something like this
stock_priceStats = table();
stock_priceStatsVars = stockprice_data.Properties.VariableNames;
for i = 1:width(stockprice_data)
colData = stockprice_data.(i);
colData = vertcat(colData{:});
stock_priceStats.(i) = [mean(colData); std(colData); min(colData); ...
quantile(colData, .25); median(colData); ...
quantile(colData, .75); max(colData)];
end
chiefjia
chiefjia 2021년 9월 29일
편집: chiefjia 2021년 9월 29일
Absolute legend, this helps a lot! Thank you!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

질문:

2021년 9월 29일

편집:

2021년 9월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by