PDA

View Full Version : Matlab while loop, Please help!


akhanijow
Apr22-10, 07:38 PM
Hi everyone,

I am writing a matlab program and am having some issues. Here is the code I have written so far:

clear all
clc


info(1) = input('What is the MARR (%)? ');
info(2) = input('What is the lifetime of the project? ');
info(3) = input('What is the initial investment ($)? ');


m=0;
while m < info(2)
m = m+1;
info(4) = m;
info(5) = input('What is the maintenance cost for year',num2str(m),' ? ');
end


functionanswer = Evaluation(info);

disp('The Present Value of the project is');
disp(functionanswer(1));



For info(5), I am trying to make it say "what is the maintenance cost for year __?"
I have tried using num2str, and may other things but cant seem to get it! Any help would be great! Thanks!

D H
Apr22-10, 08:30 PM
Have you tried reading the documentation on the input function?

akhanijow
Apr22-10, 08:35 PM
Hey,
Yes I did, I still cant seem to figure it out...I tried using the %d function and num2str, but its failed to work. I also tried using 's', but that is for a string, and I am just trying to have the input show up as:

"What is the maintenance cost for year __?"

Any idea, thanks so much!

Also, here (http://www.uni-koeln.de/rrzk/software/mathematik/matlab_help/techdoc/ref/input.html) is what I read on the input function:

D H
Apr22-10, 09:00 PM
Also, here (http://www.uni-koeln.de/rrzk/software/mathematik/matlab_help/techdoc/ref/input.html) is what I read on the input function:
So why are you trying to use it in a way that will not work? The function takes one or two arguments only. The only allowed value for the second argument is 's', and that simply bypasses the normal Matlab interpretation of the user input. The first argument is the prompt string, and it must be a string.

You need to combine multiple strings to form a single string. How do you do that? (Hint: Use the documentation.)