When I run my function I want a row vector not a column
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have a simple function that generates large numbers. The ans is a column vector but I want a row. ans' changes it to what I want but I need it to run in the function. I'm not sure how to do that?
Risposta accettata
Stephen23
il 18 Ott 2018
Modificato: Stephen23
il 18 Ott 2018
One simple solution is to use subscript indexing (but this will be quite inefficient):
function n = num(k)
n(1,1) = 1;
n(2,1) = 1;
k = 3;
while k<=100
n(k,1) = n(k-1)+n(k-2);
k = k+1;
end
function n = num(k)
n = ones(100,1); % preallocate
k = 3;
while k<=numel(n)
n(k) = n(k-1)+n(k-2);
k = k+1;
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Matrix Indexing 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!