フィルターのクリア

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 Center および File ExchangeLoops 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