Filter löschen
Filter löschen

how to storage output data from a nested parfor loop?

4 Ansichten (letzte 30 Tage)
Beatriz Sanchez
Beatriz Sanchez am 28 Jun. 2018
Bearbeitet: Beatriz Sanchez am 3 Jul. 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).

Akzeptierte Antwort

Edric Ellis
Edric Ellis am 29 Jun. 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 Kommentare
Beatriz Sanchez
Beatriz Sanchez am 3 Jul. 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 am 3 Jul. 2018
Bearbeitet: Beatriz Sanchez am 3 Jul. 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 :-)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by