how to give different combinations of inputs within the program( i want to skip input questions)?

조회 수: 4 (최근 30일)
i have a program to which i am giving two sets of inputs at a time and getting two outputs combined in a column(set 1 output on top and then set 2 output) . but every time i have to enter these two set of values in command window.
for example, if i want to enter------
set 1. for f= 7,
enter c0= 1, r0= 3
set 2. for f= 9,
enter c0= 2, r0= 4
*how can i give these inputs within the program in form of sets ?
n in program shows number of input sets* Please see the program attached
  댓글 수: 3
reshdev
reshdev 2014년 8월 23일
편집: reshdev 2014년 8월 23일
Geoff Hayes, Thanks for reply. You are right, i want to skip input questions and pass matrix like you written. thank you.
dpb
dpb 2014년 8월 23일
Still not exactly clear what you intend/want -- if you do mean "pass" in the sense of function arguments, then you would just add an array to the argument list and supply it when you call the function just as any other Matlab function. You could use the optional arguments facilities to bypass the query if the array is present or choose to make it required and just take out the user input section entirely inside the function then. Your choice depending on what you want. See
doc varargin % and friends for the optional args details

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

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 8월 23일
As reshdev had indicated in his last comment, i want to skip input questions and pass matrix like you written, then we can update the online function to accept one input only which will be a nx3 matrix where the first column is f, the second column c0, and the third column r0.
function online(inputData)
% set n based on the number of rows
n = size(inputData,1);
% row index into inputData
ridx = 1;
r = 5;
t = r-1;
output = zeros(n*r,r);
for ii = 1:r:r*n
M = zeros(t);
% initialize f, c0, r0 from row ridx of inputData
f = inputData(ridx,1);
c0 = inputData(ridx,2);
r0 = inputData(ridx,3);
ridx = ridx + 1;
% etc., rest is same
end
disp(output);
end
With the example input of
inputData = [7 1 3;
9 2 4];
online(inputData)
produces identical results to the function that queried the user to input data n times.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by