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

  • Context: MATLAB 
  • Thread starter Thread starter akhanijow
  • Start date Start date
  • Tags Tags
    Loop Matlab
Click For Summary

Discussion Overview

The discussion revolves around a MATLAB programming issue related to prompting for yearly maintenance costs within a while loop. Participants are exploring how to correctly format the input prompt to include the current year in the message displayed to the user.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Homework-related

Main Points Raised

  • One participant shares their MATLAB code and describes the issue with the input prompt for maintenance costs, seeking assistance.
  • Another participant suggests consulting the documentation on the input function as a potential solution.
  • A participant acknowledges reading the documentation but expresses continued difficulty in formatting the prompt correctly, mentioning attempts with %d and num2str.
  • Another reply critiques the approach taken by the participant, emphasizing the need to combine strings properly to create a single prompt string for the input function.

Areas of Agreement / Disagreement

Participants do not appear to reach a consensus on the best method to format the input prompt, as there are differing opinions on the correct approach to using the input function.

Contextual Notes

There are limitations regarding the understanding of how to combine strings in MATLAB, and the specific requirements of the input function are not fully resolved in the discussion.

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 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 3 ·
Replies
3
Views
2K