필터 지우기
필터 지우기

How do I use a for loop to read rows of a matrix?

조회 수: 3 (최근 30일)
Noah Acosta
Noah Acosta 2016년 6월 29일
답변: John 2016년 7월 1일
I have 5 excel files with different data, each having a matrix with 2 columns and 3204 rows. The first column is the same for each of the files, but the second column is different. I would like to create a for loop (or any loop that is efficient) to first read 1:801 rows and plot the average, then go through the loop again and average and plot 802:1602, then plot the average a third time of 1603:2403. Any advice?

답변 (1개)

John
John 2016년 7월 1일
block_size = 801;
vals = zeros(3,1);
for n = 1:5
data = xlsread(['file', num2str(n), '.xlsx']);
for m = 1:3
vals(m) = mean(data(((m-1)*block_size + 1):m*block_size, 2));
end
end
plot(vals)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by