Save data from a for loop with different dimensions?
3 次查看(过去 30 天)
显示 更早的评论
Hello I'm trying to store the data of the next loop by vectorizing each iteration:
lambda = 2;
distri= poissrnd(lambda,1,5);
xi= distri
for x = xi
r(x)= randi([1,4],1,x)
end
But I get this error: Subscripted assignment dimension mismatch.
I think is because the different results of the loop are of different sizes so they can´t be put in a single vector, so there is another way to save my data?
0 个评论
采纳的回答
Ameer Hamza
2018-6-17
编辑:Ameer Hamza
2018-6-17
Each iteration has a different number of elements so you will need a cell array. Also, you will need to change the indexing of for loop
lambda = 2;
distri= poissrnd(lambda,1,5);
xi= distri;
for x = 1:numel(xi)
r{x}= randi([1,4],1,xi(x));
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!