command window work space only
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
melissa tan
le 1 Sep 2018
Modifié(e) : Stephen23
le 6 Sep 2018
Write a function that takes numeric data as its input argument and prints a message to the Command Window stating if the number is positive, or negative, or 0. This function should transfer an output value to the Workspace ONLY when the input value is negative How do i attempt this question?
3 commentaires
Greg
le 1 Sep 2018
This sounds like a homework question. We are not here to do it for you. If you want help, try to provide the following:
- What have you tried so far?
- What went wrong with it?
- Which parts specifically do you understand?
- Which parts specifically are you having trouble with?
Réponse acceptée
Walter Roberson
le 1 Sep 2018
You need to define a function with one input and one output. The function should examine the input and disp() a message saying whether the input is negative, zero, or positive.
After that, the function should assign any arbitrary value to its output variable if the input was negative (anything is acceptable.)
If the input was zero or positive and the user asked to use the output of the function, then you should expect MATLAB to generate an error message. This is to be expected considering the requirements of the question.
For example,
>> test_pos_zero_neg(-5)
input was negative
ans =
'arbitrary output'
>> test_pos_zero_neg(5)
input was positive
(notice ans was not created in this case.)
>> result = test_pos_zero_neg(-7)
input was negative
result =
'output is not required to be consistent'
>> result = test_pos_zero_neg(7)
input was positive
Output argument "variable_to_hold_arbitrary_output" (and maybe others) not assigned during call to "test_pos_zero_neg".
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!