create multiple arrays or matrix from function input

I'm creating a function where the input 'h' is an array of numbers, and then trying to use a for loop to establish arrays with step sizes of each number listed in 'h'. for example, if the function is summoned as function([pi/2 pi/4 pi/8])
then the for loop ends up creating 3 specific arrays OR a 3X1 matrix where x1=[3*pi:pi/2:29*pi]; x2=[3*pi:pi/4:29*pi]; x3=[3*pi:pi/8:29*pi];
Is there anyway to do this? If 'h' ends up being 5 values long then I'd like it to return 5 individual arrays or a 5x1 matrix

回答 (1 件)

Jos (10584)
Jos (10584) 2018 年 5 月 9 日

0 投票

Here is an example. I suggest you store the result in a cell array where each cell can hold a vector with a different length
X = my function(h)
N = numel(h) ;
X = cell(1,N) ; % pre-allocation
for k=1:N
% fill each cell with a vector
X{k} = 3*pi:h(k):29*pi ;
end

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2018 年 5 月 9 日

回答済み:

2018 年 5 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by