From: Daniel Wells on 24 Jul 2010 02:02 Hey everybody, I've been referencing this forum for a while now for general help with programs but this is my first post. I've only take a single semester of a matlab class so not much experience but I'm trying to help one of my buddies write a program. I'm not having much success but I was hoping someone here could point me in the right direction. Here is the program in its entirety. Thanks. % supercarcompare.m by PD(2010) % Allows user to choose from 10 of the worlds best performing supercars % and compare two cars at a time. Cars are compared by price, top speed % 0-60 time, and horsepower. % All information is sourced from www.supercars.org clc clear car1 = [654400, 257, 2.7, 1183]; car2 = [17000000, 253, 2.5, 1001]; car3 = [555000, 248, 3.2, 750]; car4 = [545568, 245, 3.2, 806]; car5 = [970000, 240, 3.2, 627]; car6 = [670000, 217, 3.4, 660]; car7 = [650000, 217, 3.8, 542]; car8 = [667321, 215, 3.5, 650]; car9 = [430000, 211, 3.3, 640]; car10 = [440000, 205, 3.9, 612]; xbar = [1:4]; disp('Supercar Comparison Program by PD(2010)'); disp(char(10)); disp('This program will allow you to compare different supercars based on'); disp('horsepower, price, top speed, and 0-60 mph times. You will be able to'); disp('choose two cars at a time and their performance numbers will be shown'); disp('along with a graph showing their different attributes compared to each other.'); disp('Here are your choice of cars:'); disp('1. Shelby Ultimate Aero'); disp('2. Bugatti Veyron'); disp('3. Saleen S7'); disp('4. Koenigsegg CCX'); disp('5. McLaren F-1'); disp('6. Ferrari Enzo'); disp('7. Jaguar XJ 220'); disp('8. Pagani Zonda'); disp('9. Lamborghini Murcielago LP640'); disp('10. Porsche Carrera GT'); choice1 = input('Please select your first car to compare and enter 1-10. Enter 0 to end. '); choice2 = input('Please select your second car to compare and enter 1-10. Enter 0 to end. '); if choice1 ~= 0 || choice2 ~= 0 if choice1 >= 1 && choice1 <= 10 if choice1 == 1 disp('Price = $654,400'); disp('Top Speed = 257 mph'); disp('0-60 mph = 2.7 sec'); disp('Horsepower = 1183'); bar1 = bar(xbar,car1, 'FaceColor', 'k'); set(bar1, 'BarWidth', .5); hold on; elseif choice1 == 2 disp('Price = $1,700,000'); disp('Top Speed = 253 mph'); disp('0-60 mph = 2.5 sec'); disp('Horsepower = 1001'); bar1 = bar(xbar,car2, 'FaceColor', 'k'); set(bar1, 'BarWidth', .5); hold on; elseif choice1 == 3 disp('Price = $555,000'); disp('Top Speed = 248 mph'); disp('0-60 mph = 3.2 sec'); disp('Horsepower = 750'); bar1 = bar(xbar,car3, 'FaceColor', 'k'); set(bar1, 'Barwidth', .5); hold on; elseif choice1 == 4 disp('Price = $545,568'); disp('Top Speed = 245 mph'); disp('0-60 mph = 3.2 sec'); disp('Horsepower = 806'); bar1 = bar(xbar,car4, 'FaceColor', 'k'); set(bar1, 'Barwidth', .5); hold on; elseif choice1 == 5 disp('Price = $970,000'); disp('Top Speed = 240 mph'); disp('0-60 mph = 3.2 sec'); disp('Horsepower = 627'); bar1 = bar(xbar,car5, 'FaceColor', 'k'); set(bar1, 'Barwidth', .5); hold on; elseif choice1 == 6 disp('Price = $670,000'); disp('Top Speed = 217 mph'); disp('0-60 mph = 3.4 sec'); disp('Horsepower = 660'); bar1 = bar(xbar,car6, 'FaceColor', 'k'); set(bar1, 'Barwidth', .5); hold on; elseif choice1 == 7 disp('Price = $650,000'); disp('Top Speed = 217 mph'); disp('0-60 mph = 3.8 sec'); disp('Horsepower = 542'); bar1 = bar(xbar,car7, 'FaceColor', 'k'); set(bar1, 'Barwidth', .5); hold on; elseif choice1 == 8 disp('Price = $667,321'); disp('Top Speed = 215 mph'); disp('0-60 mph = 3.5 sec'); disp('Horsepower = 650'); bar1 = bar(xbar,car8, 'FaceColor', 'k'); set(bar1, 'Barwidth', .5); hold on; elseif choice1 == 9 disp('Price = $430,000'); disp('Top Speed = 211 mph'); disp('0-60 mph = 3.3 sec'); disp('Horsepower = 640'); bar1 = bar(xbar,car9, 'FaceColor', 'k'); set(bar1, 'Barwidth', .5); hold on; elseif choice1 == 10 disp('Price = $440,000'); disp('Top Speed = 205 mph'); disp('0-60 mph = 3.9 sec'); disp('Horsepower = 612'); bar1 = bar(xbar,car10, 'FaceColor', 'k'); set(bar1, 'Barwidth', .5); hold on; else fprintf('\nThat was not one of the choices. Please try again using 1-10 ONLY.'); disp('Here are your choice of cars:'); disp('1. Shelby Ultimate Aero'); disp('2. Bugatti Veyron'); disp('3. Saleen S7'); disp('4. Koenigsegg CCX'); disp('5. McLaren F-1'); disp('6. Ferrari Enzo'); disp('7. Jaguar XJ 220'); disp('8. Pagani Zonda'); disp('9. Lamborghini Murcielago LP640'); disp('10. Porsche Carrera GT'); choice1 = input('Please select your first car to compare and enter 1-10. Enter 0 to end. '); end else fprintf('\nThat was not one of the choices. Please try again using 1-10 ONLY.'); disp('Here are your choice of cars:'); disp('1. Shelby Ultimate Aero'); disp('2. Bugatti Veyron'); disp('3. Saleen S7'); disp('4. Koenigsegg CCX'); disp('5. McLaren F-1'); disp('6. Ferrari Enzo'); disp('7. Jaguar XJ 220'); disp('8. Pagani Zonda'); disp('9. Lamborghini Murcielago LP640'); disp('10. Porsche Carrera GT'); choice1 = input('Please select your second car to compare and enter 1-10. Enter 0 to end. '); end if choice2 >= 1 && choice2 <= 10 if choice2 == 1 disp('Price = $654,400'); disp('Top Speed = 257 mph'); disp('0-60 mph = 2.7 sec'); disp('Horsepower = 1183'); bar2 = bar(xbar,car1, 'FaceColor', 'k'); set(bar2, 'BarWidth', .5); hold off; elseif choice2 == 2 disp('Price = $1,700,000'); disp('Top Speed = 253 mph'); disp('0-60 mph = 2.5 sec'); disp('Horsepower = 1001'); bar2 = bar(xbar,car2, 'FaceColor', 'k'); set(bar2, 'BarWidth', .5); hold off; elseif choice2 == 3 disp('Price = $555,000'); disp('Top Speed = 248 mph'); disp('0-60 mph = 3.2 sec'); disp('Horsepower = 750'); bar2 = bar(xbar,car3, 'FaceColor', 'k'); set(bar2, 'Barwidth', .5); hold off; elseif choice2 == 4 disp('Price = $545,568'); disp('Top Speed = 245 mph'); disp('0-60 mph = 3.2 sec'); disp('Horsepower = 806'); bar2 = bar(xbar,car4, 'FaceColor', 'k'); set(bar2, 'Barwidth', .5); hold off; elseif choice2 == 5 disp('Price = $970,000'); disp('Top Speed = 240 mph'); disp('0-60 mph = 3.2 sec'); disp('Horsepower = 627'); bar2 = bar(xbar,car5, 'FaceColor', 'k'); set(bar2, 'Barwidth', .5); hold off; elseif choice2 == 6 disp('Price = $670,000'); disp('Top Speed = 217 mph'); disp('0-60 mph = 3.4 sec'); disp('Horsepower = 660'); bar2 = bar(xbar,car6, 'FaceColor', 'k'); set(bar2, 'Barwidth', .5); hold off; elseif choice2 == 7 disp('Price = $650,000'); disp('Top Speed = 217 mph'); disp('0-60 mph = 3.8 sec'); disp('Horsepower = 542'); bar2 = bar(xbar,car7, 'FaceColor', 'k'); set(bar2, 'Barwidth', .5); hold off; elseif choice2 == 8 disp('Price = $667,321'); disp('Top Speed = 215 mph'); disp('0-60 mph = 3.5 sec'); disp('Horsepower = 650'); bar2 = bar(xbar,car8, 'FaceColor', 'k'); set(bar2, 'Barwidth', .5); hold off; elseif choice2 == 9 disp('Price = $430,000'); disp('Top Speed = 211 mph'); disp('0-60 mph = 3.3 sec'); disp('Horsepower = 640'); bar2 = bar(xbar,car9, 'FaceColor', 'k'); set(bar2, 'Barwidth', .5); hold off; elseif choice2 == 10 disp('Price = $440,000'); disp('Top Speed = 205 mph'); disp('0-60 mph = 3.9 sec'); disp('Horsepower = 612'); bar2 = bar(xbar,car10, 'FaceColor', 'k'); set(bar2, 'Barwidth', .5); hold off; end else fprintf('\nThat was not one of the choices. Please try again using 1-10 ONLY.'); disp('Here are your choice of cars:'); disp('1. Shelby Ultimate Aero'); disp('2. Bugatti Veyron'); disp('3. Saleen S7'); disp('4. Koenigsegg CCX'); disp('5. McLaren F-1'); disp('6. Ferrari Enzo'); disp('7. Jaguar XJ 220'); disp('8. Pagani Zonda'); disp('9. Lamborghini Murcielago LP640'); disp('10. Porsche Carrera GT'); choice2 = input('Please select your second car to compare and enter 1-10. Enter 0 to end. '); end else fprintf('\nThank you for using The Supercar Comparison Program!'); end
From: Walter Roberson on 24 Jul 2010 06:20 Daniel Wells wrote: > Hey everybody, I've been referencing this forum for a while now for > general help with programs but this is my first post. I've only take a > single semester of a matlab class so not much experience but I'm trying > to help one of my buddies write a program. I'm not having much success > but I was hoping someone here could point me in the right direction. > Here is the program in its entirety. Thanks. You did not describe the difficulties you are having. An experienced Matlab user would likely find many _style_ points that could use improvement. In terms of outright bugs... trace what happens if the user enters a non-zero value for choice1 but a 0 value for choice2. And re-examine the following line: choice1 = input('Please select your second car to compare and enter 1-10. Enter 0 to end. ');
|
Pages: 1 Prev: Arduino Matlab Integration Next: Three Stage Least Squares with Non-linear Restrictions |