フィルターのクリア

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 Center および File ExchangeArgument Definitions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by