asking for inputs in a function

Lets say I have a function with no inputs. I want the function to ask for inputs each time the function is running. like for example "logically" I want something like this:
  • function [out1,out2] = test()
  • k= input('input the number of loops')
  • out1 = zeros(1,k)
  • out2 = zeros(1,k)
  • for i = 1:k
  • fprintf('input the value of A')
  • A = input('A')
  • fpritf('input the value of B')
  • B = input('B')
  • out1(i) = A
  • out2(i) = B
  • end
  • end
Thanks

댓글 수: 4

Fangjun Jiang
Fangjun Jiang 2011년 11월 9일
What is your question?
John D'Errico
John D'Errico 2011년 11월 9일
It is a god-awfully terrible interface that should never be pushed on your users, at least anyone with an opinion you care about, but you can do it if you want. In fact, you already have the basic idea. So what is your question?
Yaman
Yaman 2011년 11월 9일
I know it is pointless but I was asked something like this at an interview. When the function runs it doesn't ask for input A or input B. It straight up jumps to an error saying no input for A was found.
Thanks
Yaman
Yaman 2011년 11월 9일
never mind it somehow decided to run... Thanks for the help anyway.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

질문:

2011년 11월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by