필터 지우기
필터 지우기

how to divide excel files in matlab into uneven groups

조회 수: 2 (최근 30일)
Abebe kebede
Abebe kebede 2015년 7월 7일
답변: Star Strider 2015년 7월 7일
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

채택된 답변

bio lim
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

추가 답변 (1개)

Star Strider
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.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by