writing a loop in matlab for huge excel data to get average of 4 numbers repeatedly in the column all the way to end

I am trying to fetch a column from excel with rows more than 17500. Now problem is that when i call it in MATLAB , it does not gives me whole matrix with all data. it fetches data from somewhere in middle.
Now the real problem is that i have to add up 4 numbers in the column and get average , save it in another column and proceed to next consecutive set of numbers and repeat again till the end..How could i do that in MATLAB .
so far i have done is this:
clc
g=xlsread('Data.xlsx',1,'E1:E17500');
x=1;
for i = 1:(17500/4) %as steps has to be stepped at 4 since we need avg of 4
y{i}=((g{x}+g{x+1}+g{x+2}+g{x+3})/4);
x=x+4;
end
xlswrite('Data.xlsx', y, 1, 'F1:F4375');
it fetches the data in g but then gives me error. I am unable to run this right now.Please help me solve this problem as i am just a rookie. Thank you.

 Accepted Answer

The 'xlsread' function returns a 'double' format array, not a cell array, and therefore you should be using parentheses, not curly brackets: g(x) and not g{x}.
Alternatively you can avoid the for-loop with this single line:
y = mean(reshape(g,4,[])).';

More Answers (0)

Categories

Products

Community Treasure Hunt

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

Start Hunting!