Matlab function

I'm relatively new to Matlab
I need to carry out the following task and I'm just partially done.I'd be happy if someone can help me as stated;
Task I'm doing is;
1) I have 2 functions A and B 2)Function A does some calculations. 3)After doing those calculations function A calls B- no arguments given to B 4)At this point Function B should prompt the user for some inputs 5)The user should enter the inputs through the coommand window 6)The user inputs are returned from function B to function A
Can anyone please advice how to carry out steps 4,5,6? Please help.
shalini

2 Comments

Andrew Newell
Andrew Newell on 7 Mar 2012
See http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer.
Shalini
Shalini on 7 Mar 2012
Sorry, but I was just trying to ask how to prompt the user for input values in step 4. I did see the video for matlab programming but couldn't get this..anyways, will ebgrateful if helped

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 7 Mar 2012
There is a function called input(). Try that.
From its help:
reply = input('Do you want more? Y/N [Y]: ', 's');
if isempty(reply)
reply = 'Y';
end

6 Comments

Shalini
Shalini on 7 Mar 2012
So, if I put it as:
reply=input('Enter the value of A','s');
Then reply will be returned as 'Y'
Where and when will the user eneter the value of A in command window?
Image Analyst
Image Analyst on 7 Mar 2012
You said A was a function, so you have to define it in an m-file, something like this:
function [output1 output2] = A(input1, input2)
output1 = 2*input1;
output2 = input2 / 10;
The user does not enter A - the programmer (you) does.
Shalini
Shalini on 7 Mar 2012
Sorry for the confusion:
I want a variable to be eneterd in the command window and I want the function B to prompt this to the user like:
reply=input('Enter the value of variable my_variable','s');
USer eneters in command window (supossing a number 6)
then 6 should get assigned to my_variable..
Image Analyst
Image Analyst on 7 Mar 2012
Try this:
% Define a
a = 10
% Ask user for a number, b
b = input('Enter the value of variable "b" ')
% Multiply the two.
c = a * b
Shalini
Shalini on 7 Mar 2012
Thanks a lot, will try in next 4 hours (I do not have Matlab where I'm working now).
Can the user input a vector as well?
I would guess yes, right?
Image Analyst
Image Analyst on 7 Mar 2012
Stangely, no. You have to do it like this:
% Ask user for several numbers, b
string_b = input('Enter the several numbers ', 's')
double_b = str2num(string_b)
% Multiply the two.
c = a * double_b

Sign in to comment.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Asked:

on 7 Mar 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!