필터 지우기
필터 지우기

varargout-varargin commands for easy calculation

조회 수: 2 (최근 30일)
Nik Sam
Nik Sam 2016년 5월 20일
편집: Walter Roberson 2016년 5월 20일
Hello everyone,
I believe that my question is not hard...
I have this code
function [varargout] = trg (varargin)
A1=varargin(1,1)
A2=varargin(1,2)
A3=varargin(1,3)
a=input('Value= ')
varargout=[(A2{:}-A1{:})*a+A1{:},A3{:}-(A3{:}-A2{:})*a]
end
this code can provide for a=0;
[
k]=trg(1,2,3)
a=0
k=
1 3
I want to have as inputs for example [1 2 3] [0 2.5 5] and as outputs lets say [k p] or more inputs and outputs
For example if
[k p]=tgr([1 2 3],[0 2.5 5]) and for a=0; The desirable results should be
k =
1 3
p =
0 5
A1 must take the first number of [1 2 3] A2 the second and A3 the third and the same to [0 2.5 5] and for more inputs.

답변 (1개)

Geoff Hayes
Geoff Hayes 2016년 5월 20일
Nik - rather than using a variable number of inputs (and so outputs), why don't you just have a single input parameter that is an nx3 array. Your output would then be a nx2 array. For example,
function [dataOut] = trg (dataIn)
n = size(dataIn,1);
dataOut = zeros(n,2);
for k=1:n
A1 = dataIn(k,1);
A2 = dataIn(k,2);
A3 = dataIn(k,3);
a=input('Value= ');
dataOut(k,:) = [(A2-A1)*a+A1,A3-(A3-A2)*a];
end
If you then call the above as
>> trg([1 2 3;0 2.5 5])
ans =
1 3
0 5
you get the expected answer.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by