Hi, can someone help me, i must implement a matlab function with varargin and the input and the output arguments must be a vector. Which brackets should i choose to implement a vector in a varagin function The code below should show, how i would try to convert the temperature from celsius to fahrenheid. Thanks for your help
function [ output ] = c2f(varargin) %UNTITLED Summary of this function goes here % Detailed explanation goes here
f=convtemp([nargin],'C','F'); output=f
end

 채택된 답변

Jan
Jan 2017년 4월 10일
편집: Jan 2017년 4월 11일

0 개 추천

You forgot to mention what you want to provide as input and get as output. I guess you do not need varargin at all:
function output = c2f(Data)
output = convtemp(Data, 'C', 'F');
end
If you really want to provide several inputs, do you want to reply a cell array as output? Or a list of sepearate variables? For the latter:
function varargout = c2f(varargin) % [EDITED, typo, was "nargin"]
if nargout ~= nargin
error('Number of outputs must equal the number of inputs.');
end
for iArg = 1:nargin
varargout{iArg} = convtemp(varargin{iArg}, 'C', 'F');
end
end

댓글 수: 4

Thom
Thom 2017년 4월 10일
Thanks for your answer, but how can i do, if a have 8 input datas?
Thom
Thom 2017년 4월 11일
Yes exactly i want to reply a cell array as output.
Jan
Jan 2017년 4월 11일
편집: Jan 2017년 4월 11일
To get a cell array as output:
function C = c2f(varargin)
C = cell(1, nargin);
for iArg = 1:nargin
C{iArg} = convtemp(varargin{iArg}, 'C', 'F');
end
end
Now this can be called by:
Temperature = c2f(0:5, [123.1, 123.4, 123.9], Inf, -17:2:100)
Thom
Thom 2017년 4월 11일
Thanks for your help

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Argument Definitions에 대해 자세히 알아보기

질문:

2017년 4월 10일

댓글:

2017년 4월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by