Filter löschen
Filter löschen

How to approach a "for" loop problem with imported data?

1 Ansicht (letzte 30 Tage)
Miranda Moore
Miranda Moore am 29 Nov. 2016
Beantwortet: Walter Roberson am 29 Nov. 2016
I have copied and pasted the problem itself below.
Every summer, many people travel by road to various locations across the country. With low fuel prices this summer, there will be lots of travel. The purpose of this program is to determine the total miles of travel and also compute the cost of travel using various travel route options. The excel sheet named project3.xlsx has data for this work. The table represents 55 families travel plans. Each family is identified by a family ID. Each travel plan consists of 10 road segments whose distances are given in miles. Column 11 is the average speed of the family and column 12 is the fuel efficiency of the family’s vehicle. For example, for family 1, the average speed is 65mph and they have a vehicle that does 35 miles per gallon. Write a function called summetravel that uses a for loop to generate the table below. Your table should show all the outputs from 1 to 55. Use $2/gallon as the average fuel cost.
So an example of the data itself is:
FAMILY 1 2 3 4 5 6 7 8 9 10 11 12
1 40 150 70 100 140 202 51 44 12 95 65 35
2 100 121 57 105 66 182 54 87 8 141 75 20
The table that the code is supposed to result in includes the total miles driven, total hours, and predicted fuel cost. So I understand the main concept behind it, assigning each group variables then using different operations such as adding road segments and dividing total distance to find other quantities. I am just unsure of how to do this doing a "for" loop and how to adjust for each variable accessing different data from the excel spreadsheet.
I do not want anyone to do this problem for me
I just have absolutely no idea where to even start. Every code I have tried has given me countless errors and gotten me nowhere closer to a solution. I appreciate any help I can get. Thank you.

Antworten (1)

Walter Roberson
Walter Roberson am 29 Nov. 2016
Start by using
num = xlsread('project3.xlsx');
There does not seem to be much else to the question beyond summing along rows and doing some minor calculation based upon the given average speed. There does not seem to be any point in using group variables -- not unless the data is quite different than what you posted.
It looks to me as if you can vectorize everything. You could vectorize the display, too, but you should probably do that at least in a for loop.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by