how to storage output data from a nested parfor loop?

2 visualizaciones (últimos 30 días)
Beatriz Sanchez
Beatriz Sanchez el 28 de Jun. de 2018
Editada: Beatriz Sanchez el 3 de Jul. de 2018
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).

Respuesta aceptada

Edric Ellis
Edric Ellis el 29 de Jun. de 2018
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 comentarios
Beatriz Sanchez
Beatriz Sanchez el 3 de Jul. de 2018
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 el 3 de Jul. de 2018
Editada: Beatriz Sanchez el 3 de Jul. de 2018
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 :-)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by