how do I get i to loop through the 55 columns of the excel file one by one. I want i to correspond to the values of the 55 columns to calculate miles driven
1 次查看(过去 30 天)
显示 更早的评论
filename = 'project3data.xlsx';
num = xlsread('project3data.xlsx');
for i = 1:55
milesdriven = sum(num(2,2:11))
end
0 个评论
回答(1 个)
Walter Roberson
2016-12-4
Guessing that you only want rows 2 to 11:
milesdriven(i) = sum(num(2:11, i))
4 个评论
Walter Roberson
2016-12-4
With no loop:
%adjust these four lines according to your needs
first_row_with_data = 2;
last_row_with_data = size(num, 1);
first_column_with_data = 2;
last_column_with_data = size(num, 2) - 1;
milesdriven = sum( num(first_row_with_data : last_row_with_data, first_column_with_data, last_column_with_data), 2) );
This will sum for each row.
This assumes that your file matches http://www.mathworks.com/matlabcentral/answers/314481-solving-a-for-loop-problem-with-imported-data
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!