Matlab while loop, Please help!

  • MATLAB
  • Thread starter akhanijow
  • Start date
  • #1
7
0

Main Question or Discussion Point

Hi everyone,

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

Code:
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!
 

Answers and Replies

  • #2
D H
Staff Emeritus
Science Advisor
Insights Author
15,393
683
Have you tried reading the documentation on the input function?
 
  • #3
7
0
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, http://www.uni-koeln.de/rrzk/software/mathematik/matlab_help/techdoc/ref/input.html" is what I read on the input function:
 
Last edited by a moderator:
  • #4
D H
Staff Emeritus
Science Advisor
Insights Author
15,393
683
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.)
 
Last edited by a moderator:

Related Threads on Matlab while loop, Please help!

Replies
1
Views
3K
Replies
1
Views
2K
Replies
1
Views
17K
  • Last Post
Replies
1
Views
6K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
1
Views
603
  • Last Post
Replies
5
Views
4K
  • Last Post
Replies
4
Views
4K
Replies
7
Views
832
Replies
4
Views
6K
Top