varargout-varargin commands for easy calculation
2 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Geoff Hayes
on 20 May 2016
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.
0 Comments
See Also
Categories
Find more on Argument Definitions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!