Go Back   Christian Guitar Forum > Community > Academic > Computers
Register FAQ Members List Calendar Arcade Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old 10-03-2011, 02:54 PM   #1
IS NO SOFT DRINK
 
MountainDew's Avatar
 

Joined: Jul 2007
Location: Drinking Mountain Dew
Posts: 390
Send a message via Skype™ to MountainDew
Matlab Question

Does there happen to be any Matlab gurus out there? I'm taking a Matlab class and I have a project I'm supposed to complete that has me absolutely stumped. I don't necessarily want anyone to do this whole thing for me, but I would appreciate any hints and help you might be able to give me. The Matlab script has to do the following:

%%%%%Create a program that creates a countdown from a user-generated integer. If the number is negative, then the program should quit. If it's not, the program should then display the remaining time after every second of elapsed time. It should print "Blast off!" when the remaining time is zero and ask the user to input another number.%%%%%

I cannot figure this out and it's driving me crazy. Any help would be greatly appreciated!

__________________
"Always out-manned, never out-gunned"

"The most dangerous weapon in the world is a US Marine and his rifle."

"The Marines know how to use their bayonets. The Army's bayonets might as well be used as paper weights."

"It's God's job to judge the terrorists. It's the Marines job to arrange the meeting."

My friends blog (with a few random posts by me!)
MountainDew is offline   Reply With Quote
Sponsored Links
Old 10-03-2011, 04:20 PM   #2
PhD candidate
 
to_be_released's Avatar
 

Joined: Aug 2010
Location: Auckland, New Zealand
Posts: 312
Well, you've got a few main things to figure out. Firstly, you need user input, Request user input - MATLAB should help there.

Secondly you need to figure out the timer, have a look at Using a MATLAB Timer Object :: Program Scheduling (MATLAB®)

A simple while loop with a conditional statement along the lines of "while (number>=0)" should let you exit with negatives.

I'd perhaps suggest putting some form of rounding in, just in case the user puts in something that isn't an integer.

That should help you piece it together.

(by the way, google is a coders best friend. Todays help brought to you by Let me google that for you and Let me google that for you )
to_be_released is offline   Reply With Quote
Old 10-03-2011, 04:26 PM   #3
Be happy
 
bobthecockroach's Avatar
 

Joined: Apr 2001
Location: Louisiana
Posts: 19,912
I don't know Matlab, but for something simple like this, I would look for a sleep/pause/wait statement rather than mess with a timer.
__________________
Some things are meant together, some things are better apart
Some things are easy, when other times they are hard
But that doesn’t mean what’s hard isn’t what’s meant to be
- Al Lewis
bobthecockroach is offline   Reply With Quote
Old 10-03-2011, 04:39 PM   #4
PhD candidate
 
to_be_released's Avatar
 

Joined: Aug 2010
Location: Auckland, New Zealand
Posts: 312
Good point Bob, pause appears to be the function to use (and it's use can actually be seen in the example for the timer that I linked above).

Something like

foo=10;
while(foo>0)
disp(foo)
foo=foo-1;
pause(1)
end
disp('Blast off!')

should work
to_be_released is offline   Reply With Quote
Old 10-03-2011, 05:08 PM   #5
IS NO SOFT DRINK
 
MountainDew's Avatar
 

Joined: Jul 2007
Location: Drinking Mountain Dew
Posts: 390
Send a message via Skype™ to MountainDew
Thanks a lot guys. Taking what to_be_released suggested, I added a few lab-specific things and came up with this.

function lab4program1

clc

disp('Welcome to the countdown timer program:');
time = input('Enter a time (seconds) or negative number to quit:');

if time < 0
disp('Time must be positive');
return
end


while time > 0
disp(time)
time = time - 1;
pause(1)
end

disp('Blast off!');
disp(' ');
disp('Thank you');

end

The lab says nothing about having to deal with non-integer inputs, so I'm not sure if I should do nothing, just have the input rounded, or display an error message if it's not an integer.
__________________
"Always out-manned, never out-gunned"

"The most dangerous weapon in the world is a US Marine and his rifle."

"The Marines know how to use their bayonets. The Army's bayonets might as well be used as paper weights."

"It's God's job to judge the terrorists. It's the Marines job to arrange the meeting."

My friends blog (with a few random posts by me!)
MountainDew is offline   Reply With Quote
Old 10-03-2011, 06:20 PM   #6
Be happy
 
bobthecockroach's Avatar
 

Joined: Apr 2001
Location: Louisiana
Posts: 19,912
Spec says ask for another number, so you'll need to loop the whole thing too.
__________________
Some things are meant together, some things are better apart
Some things are easy, when other times they are hard
But that doesn’t mean what’s hard isn’t what’s meant to be
- Al Lewis
bobthecockroach is offline   Reply With Quote
Old 10-04-2011, 09:02 AM   #7
IS NO SOFT DRINK
 
MountainDew's Avatar
 

Joined: Jul 2007
Location: Drinking Mountain Dew
Posts: 390
Send a message via Skype™ to MountainDew
Quote:
Originally Posted by bobthecockroach View Post
Spec says ask for another number, so you'll need to loop the whole thing too.
Thanks, I missed that part. I've revised it to include that spec.

I took a look at the second part of the lab and it makes absolutely no sense to me. I am given a 6x5 matrix of 1s and 0s. I have to create a program that draws a red square if the number is a 1 and a red square if the number is zero. They give me a "template" for the code, but I can't make heads or tails out of it. Here's the template code they give me.

function lab4program2
level_map = [0 0 0 0 0;0 1 0 1 0;1 0 1 0 1; 0 1 0 1 0;0 0 1 0 0];
map_size = size(level_map);
a = axes();
axis(a,[0,6,0,6]);
hold on;
%your loop goes here
end
%draws a square on axes, a, at location x,y with radius r, and 3 element
%color, e.g. [0,0,1] for blue, or [1,0,0] for red
function draw_square(a,x,y,r,c)
plot([x-r,x-r,x+r,x+r,x-r],[y+r,y-r,y-r,y+r,y+r],'-','parent',a,'color',c);
end


Any help would be greatly appreciated guys!
__________________
"Always out-manned, never out-gunned"

"The most dangerous weapon in the world is a US Marine and his rifle."

"The Marines know how to use their bayonets. The Army's bayonets might as well be used as paper weights."

"It's God's job to judge the terrorists. It's the Marines job to arrange the meeting."

My friends blog (with a few random posts by me!)
MountainDew is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -6. The time now is 01:12 AM.