Referring to specific input in loop

1 回表示 (過去 30 日間)
Ahmed Abdulla
Ahmed Abdulla 2020 年 6 月 8 日
コメント済み: Stephen23 2020 年 6 月 8 日
I am writing a function and the input arguments are Data1 Data2 Data3 Data4 .... DataN. I am running a loop from i=1:N and one of the commands in this loop is to get the size(Datai) but im not sure how to refer to the specifc Data matrix based on the value of i in the loop.
  2 件のコメント
KSSV
KSSV 2020 年 6 月 8 日
編集済み: KSSV 2020 年 6 月 8 日
How/ Why there is Data1, Data2, ...DataN?
This is not allowed/ comfortable. Rather use Data{1}, Data{2},.....Data{N}. This is called cell.
Stephen23
Stephen23 2020 年 6 月 8 日
"...the input arguments are Data1 Data2 Data3 Data4 .... DataN."
Numbering variable names like that is a sign that you are doing something wrong.
Most likely your code would be simpler and more efficient if you just used one container array, e.g. a cell array.

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

採用された回答

Mohammad Sami
Mohammad Sami 2020 年 6 月 8 日
If you want to have variable number of arguments, perhaps you want to use varargin instead in your function signature.
function out = f_take_n_args(varargin)
for i = 1:length(varargin)
Datai = varargin{i};
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Objects についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by