create multiple arrays or matrix from function input
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposte (1)
Jos (10584)
il 9 Mag 2018
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
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!