MATLAB How to Correctly Prompt for Yearly Maintenance Costs in a MATLAB While Loop?

  • Thread starter Thread starter akhanijow
  • Start date Start date
  • Tags Tags
    Loop Matlab
AI Thread Summary
The discussion centers on a MATLAB programming issue where the user is attempting to create a dynamic input prompt for maintenance costs in a loop. The user wants the prompt to read, "What is the maintenance cost for year __?" but is struggling to format the string correctly. Despite trying various methods, including num2str and the %d function, the user has not succeeded. Responses emphasize the importance of understanding the input function's requirements, specifically that it accepts only one or two arguments, with the second being 's' for strings. Participants suggest combining multiple strings to create the desired prompt and recommend consulting the documentation for guidance on string concatenation in MATLAB.
akhanijow
Messages
7
Reaction score
0
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 can't seem to get it! Any help would be great! Thanks!
 
Physics news on Phys.org
Have you tried reading the documentation on the input function?
 
Hey,
Yes I did, I still can't 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:
akhanijow said:
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:

Similar threads

Replies
4
Views
1K
Replies
5
Views
3K
Replies
4
Views
3K
Replies
3
Views
2K
Replies
1
Views
3K
Back
Top