how to divide excel files in matlab into uneven groups
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
bio lim
2015-7-7
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 个评论
更多回答(1 个)
Star Strider
2015-7-7
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!