How do I use a for loop to read rows of a matrix?
1 次查看(过去 30 天)
显示 更早的评论
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
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Geographic Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!