how to divide excel files in matlab into uneven groups
1 view (last 30 days)
Show older comments
i have excel file with 3000 row and 1 column. once i import it using xlsread (data),i want to calculate the average values based on the range in i, i= 1,120,500, 1500, 2300,3000. That means the first average value contains the data from row 3 to row 120 and the second from 121 to 500 and so on. so at last the average values can be a column vecor with 5 rows .Could you please help. Thanks
0 Comments
Accepted Answer
bio lim
on 7 Jul 2015
Hello. Although I wouldn't recommend loops, since no one replied, I'll clumsily do it.
i = [3 120 121 500 501 1500 1501 2300 2301 3000]; % Your range 3-120, 121-500 etc.
str = cell(1, 10); % Create a cell array
for n = 1 : length(str)
str{n} = strcat('A', num2str(i(n))); % A3, A120, A121 etc.
end
data = cell(1, 5);
average = zeros(5, 1); % Creat an array of zeros
for p = 1 : length(data)
data{p} = xlsread('filename.xlsx', [str{2*p-1}, ':', str{2*p}]);
average(p) = mean(data{p});
end
0 Comments
More Answers (1)
Star Strider
on 7 Jul 2015
You can do it without loops, using cell arrays:
V = randi(99, 3000, 1); % Create Data
Partitions = diff([0 120 500 1500 2300 3000]); % Define Vector Partitions
C = mat2cell(V, Partitions, 1); % Create Cell Arrays
Result = cellfun(@mean, C); % Take Means
The ‘Result’ assignment is the output, containing the means of the partitioned vector.
0 Comments
See Also
Categories
Find more on Data Import from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!