how to storage output data from a nested parfor loop?

2 次查看(过去 30 天)
Hi, so I have something like this:
m=[150; 300; 0]
m(1)=180
vec=[-180 -36 0 36 180]
d=1000
for i=1:5
dm2=vec(:,i)
m(2)=dm2+m(1)
for ind=1:5
dm3=vec(:,ind)
m(3)=dm3+m(1)
parfor k=1:5
a=randi (1000,3,1)
out=floor(a/sum(a)*d)
out(1)=out(1)-sum(out)+d
x= out .* m
x'
end
end
end
But obviously, the value of x' it's replaced on each iteration, how can I storage this data? I was thinking on storage it in a multidimensional array like x(25,3,5).

采纳的回答

Edric Ellis
Edric Ellis 2018-6-29
In this case, x is a 3-element vector. You can store each of these vectors in a 4-D array like so:
for i = 1:5
...
for ind = 1:5
...
parfor k = 1:5
...
output(i, ind, k, :) = x;
end
end
end
  2 个评论
Beatriz Sanchez
Beatriz Sanchez 2018-7-3
Thank you very much for your help. Unfortunately it gives me an error, it says:
'Error using pueba>(parfor consume)
Assignment has more non-singleton rhs dimensions than non-singleton subscripts'
Error in pueba (line 14) parfor k= 1:5'
Beatriz Sanchez
Beatriz Sanchez 2018-7-3
编辑:Beatriz Sanchez 2018-7-3
alright, I stablish F before the loop like this:
F=zeros(5,5,5,3)
for i=5
...
for ind=5
...
parfor k=5
...
F(i,ind,k,:)=X'
end
end
end
and the code runs perfectly, only that the 'k' (or third) dimension appers with a random order, but that is not important for what I want, and I figure that's because the parfor loop run independently from each iteration.
Anyways, I appreciate a lot your help, thank you :-)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by