필터 지우기
필터 지우기

how to storage output data from a nested parfor loop?

조회 수: 4 (최근 30일)
Beatriz Sanchez
Beatriz Sanchez 2018년 6월 28일
편집: Beatriz Sanchez 2018년 7월 3일
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