Unknown amount of function inputs as a function input?

I have a function with a nesting inbuilt Matlab function. My function input has to be used as an input to another function, but the number of function inputs is unknown. Here is my some of my code:
function [ output_args ] = funcName( other_inputs, varargin )
%
% some other code using other_inputs
%
fileID = fopen(file_name);
data = textscan(idfileID, formatSpec, varargin{1}, varargin{2} .. varargin{N});
fclose(id);
end
In my case I'm using the textscan function. But the amount of inputs for that function is unknown. Is there some work around this? I have tried to replace the varargin with the use of eval and a string input, but with no luck.

3 件のコメント

Walter Roberson
Walter Roberson 2017 年 4 月 6 日
Are you looking for
data = textscan(idfileID, formatSpec, varargin{:});
?
Stephen23
Stephen23 2017 年 4 月 6 日
編集済み: Stephen23 2017 年 4 月 6 日
This is easy with Comma-Separated Lists (as Walter Roberson and Guillaume have shown):
Jakob Sutton
Jakob Sutton 2017 年 4 月 6 日
Oh yeah... must have gotten a brain fart or something. Thank you xD

サインインしてコメントする。

回答 (1 件)

Guillaume
Guillaume 2017 年 4 月 6 日
編集済み: Guillaume 2017 年 4 月 6 日

0 投票

This page more or less explains the concept. Use the expansion of cell arrays in comma-separated-list:
data = textscan(idfileID, formatSpec, varargin{:})
varargin{:} is automatically expanded by matlab into varargin{1}, varargin{2}, ..., varargin{end}
Note that it works with any cell array (and structures), not just varargin.

カテゴリ

ヘルプ センター および File Exchange で Large Files and Big Data についてさらに検索

質問済み:

2017 年 4 月 6 日

コメント済み:

2017 年 4 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by