필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
filename = 'project3data.xlsx';
num = xlsread('project3data.xlsx');
for i = 1:55
milesdriven = sum(num(2,2:11))
end

답변 (1개)

Walter Roberson
Walter Roberson 2016년 12월 4일
Guessing that you only want rows 2 to 11:
milesdriven(i) = sum(num(2:11, i))
  댓글 수: 4
Khalid Tewfik
Khalid Tewfik 2016년 12월 4일
Yeah you're right I meant rows, but the second bit of code isn't working either
Walter Roberson
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by