Advanced Engineering Tech For the more hardcore LS1TECH residents

(HELP)Who knows anything about MATLAB?

Thread Tools
 
Search this Thread
 
Old Feb 13, 2010 | 04:55 PM
  #1  
Sammyboy's Avatar
Thread Starter
TECH Regular
iTrader: (9)
 
Joined: Jul 2008
Posts: 432
Likes: 0
From: Knoxville, TN
Default (HELP)Who knows anything about MATLAB?

Question: Write a function named mymax that takes as input a list of numbers and returns the maximum value in the list and its location (index). You may NOT use Matlab's max command. Your function should show an error message and return 0 and 0 if it is called with the wrong number of inputs or if the input isn't a one row matrix.

What I have so far:

function Q1=mymax[list]
%input a list of values
%output-maximum value
%output-value position
x_max=list(1)
% sets the initial value of the list to the maximum value
for ii = 1:length(list)
% runs the if statement below for the entire list of numbers
if x_max < x(ii)
% if statement which checks whether the current value is higher than the next value
x_max = x(ii)
% if x(3) is higher than x(1), and so on, then x_max will become the third value.
end
for list(1)< list(i)
x_max=list(i)
if list(x)
error('wrong number of inputs')
i=0;
return;
end
if
error('the input isnt a one row matrix')
i=0;
return;
end
Reply
Old Feb 16, 2010 | 10:46 AM
  #2  
MikeMoss's Avatar
On The Tree
 
Joined: Jul 2007
Posts: 101
Likes: 0
From: Kansas City, Kansas
Default

This sounds like a HW assignment. Why else would you not be aloud to use the max command.


function Q1 = mymax[list]

%output-maximum value
%output-value position


x_max=list(1)

% sets the initial value of the list to the maximum value

for ii = 1:length(list)

% runs the if statement below for the entire list of numbers

if x_max < x(ii), % I think you want list(ii) not x(ii), bc you do not have a variable x.

% if statement which checks whether the current value is higher than the next value

x_max = x(ii)

% if x(3) is higher than x(1), and so on, then x_max will become the third value.

end % This just ends the if statement.

for list(1) < list(i) % were you wanting a nested for for loop? What is i?

x_max = list(i)

if list(x) % You havent declared a variable x.
error('wrong number of inputs')
i=0;
return;
end
if % No parameters for the if statement
error('the input isnt a one row matrix')
i=0;
return;
end
Your errors could be because Im not sure if the varibles are passing outside of the of the for loops. I havent taken a MATLAB class since last spring so I dont remember. The variables might need to be declared as global.

Sorry if nothing I added helped. I am by no means a MATLAB expert.

Is there any more info about the problem?

Could you post your mymax function? Edit: this is the mymax function.

Use the MATLAB help.

Last edited by MikeMoss; Feb 16, 2010 at 11:57 AM.
Reply
Old Feb 18, 2010 | 03:11 AM
  #3  
Beaflag VonRathburg's Avatar
OWN3D BY MY PROF!
iTrader: (176)
 
Joined: Feb 2006
Posts: 9,146
Likes: 3
From: Jax Beach, Florida
Default

Don't get caught by your teacher. That's all I have to say on the subject. You may end up with a fancy new user title.
Reply
Old Feb 21, 2010 | 04:38 PM
  #4  
Ryans99ls1's Avatar
TECH Fanatic
15 Year Member
Liked
Loved
Community Favorite
iTrader: (16)
 
Joined: Dec 2007
Posts: 1,594
Likes: 271
From: OH & MI
Default

Originally Posted by MikeMoss
This sounds like a HW assignment. Why else would you not be aloud to use the max command.



Your errors could be because Im not sure if the varibles are passing outside of the of the for loops. I havent taken a MATLAB class since last spring so I dont remember. The variables might need to be declared as global.

Sorry if nothing I added helped. I am by no means a MATLAB expert.

Is there any more info about the problem?

Could you post your mymax function? Edit: this is the mymax function.

Use the MATLAB help.
It sounds like you are referring more to a C++ type program.. but idk im VERY new to C++ and more in depth programming. i didnt really read into OP's program much though because i recently just stopped using MATLAB and switched to C++(which im not a fan of) so my MATLAB skills are fading. ill have to think about this one and get back to you(the OP)
Reply




All times are GMT -5. The time now is 10:40 AM.

story-0
Amazing '71 Camaro Restomod Is Modern Muscle Car Under the Skin

Slideshow: This heavily modified 1971 Camaro mixes classic muscle car styling with a fifth-generation Camaro interior and modern LS3 power.

By Verdad Gallardo | 2026-05-12 18:06:42


VIEW MORE
story-1
6 Common C5 Corvette Failures and What's Involved In Repairing Them

Slideshow: From wobbling harmonic balancers to failed EBCMs, these are the issues that define long-term C5 ownership and what repairs typically involve.

By Pouria Savadkouei | 2026-05-07 18:44:57


VIEW MORE
story-2
Retro Modern Bandit Pontiac Trans AM Comes With Burt Reynolds' Autograph

Slideshow: A modern Camaro transformed into a retro icon, this limited-run "Bandit" build blends nostalgia with brute force in a way few revivals manage.

By Verdad Gallardo | 2026-04-21 13:57:02


VIEW MORE
story-3
Top 10 Greatest Cadillac V Series Performance Models Ever, Ranked

Slideshow: Cadillac didn't just crash the high-performance luxury vehicle party, it showed up loud, supercharged, and occasionally a little unhinged...

By Pouria Savadkouei | 2026-04-16 10:05:15


VIEW MORE
story-4
Top 10 Most Powerful Chevy Trucks Ever Made!

Slideshow: Top ten most powerful Chevy trucks ever made

By | 2026-03-25 09:22:26


VIEW MORE
story-5
Hennessey's New Supercharged Silverado ZR2 Has 700 HP

Slideshow: Hennessey has turned the Silverado ZR2 into a 700-hp off-road monster with supercharged V8 power and a limited production run.

By Verdad Gallardo | 2026-03-24 18:57:52


VIEW MORE
story-6
Coachbuilt N2A Anteros Is an LS2-Powered C6 Corvette In Italian Clothes

Slideshow: A one-off sports car that looks like a vintage Italian exotic-but hides a C6 Corvette underneath-just sold for the price of a new mid-engine Corvette.

By Verdad Gallardo | 2026-03-23 18:53:41


VIEW MORE
story-7
Awesome K5 Blazer Restomod Comes With C7 Corvette Power

Slideshow: A heavily reworked 1972 K5 Blazer swaps its off-road roots for a low-slung street-focused build with modern V8 power.

By Verdad Gallardo | 2026-03-09 18:08:45


VIEW MORE
story-8
10 Camaros You Should Never Buy

Slideshow: There are thousands of used Camaros on the market but we think you should avoid these 10

By | 2026-02-17 17:09:30


VIEW MORE
story-9
10 LS Engine Myths That Refuse to Die

Slideshows: Which one of these myths do you believe?

By Verdad Gallardo | 2026-01-28 18:10:11


VIEW MORE