replacing matrix rows in a loop
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Sean de Wolski
2013-2-11
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
0 个评论
更多回答(1 个)
Azzi Abdelmalek
2013-2-11
k=10;
n=20;
X=rand(1,n)
out=cell2mat(arrayfun(@(y) he_polynomial(1,k,X(y)),(1:n)','un',0))
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!