replacing matrix rows in a loop

13 vues (au cours des 30 derniers jours)
Fred
Fred le 11 Fév 2013
Hi,
I am trying to build a n*k matrix but each row are produced by a function which has a 1*k output. How can I build that? I tried to build a n*k matrix of zeros and replace rows in a loop but since the dimensions are not same, I can't replace rows!
Thanks
  2 commentaires
Azzi Abdelmalek
Azzi Abdelmalek le 11 Fév 2013
Provide a short example
Fred
Fred le 11 Fév 2013
Modifié(e) : Fred le 11 Fév 2013
This is my function which is a polynomial with k outputs for each X(i) i=1:n and my matrix will be n*k
This is a row for a X(i): [P(1), P(2), ...P(k)]=he_polynomial(1, k, X(i))

Connectez-vous pour commenter.

Réponse acceptée

Sean de Wolski
Sean de Wolski le 11 Fév 2013
X = zeros(100,10); %preallocate
for ii = 1:size(X,1) %loop over 100 rows
X(ii,:) = rand(1,10); %insert 10 random numbers
end

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 11 Fév 2013
k=10;
n=20;
X=rand(1,n)
out=cell2mat(arrayfun(@(y) he_polynomial(1,k,X(y)),(1:n)','un',0))

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by