Classification of variables in parfor-Loop

Good day,
I am reaching out because I have some problems with the Classification of variables in parfor-Loop.
I have declared the variable V outside the parfor-Loop in order to make it a Sliced output Variable, but a warning comes up saying: "The parfor-Loop cannot run due to the way variable, 'V' is used".
I have tried to declare V (line 1), inside the parfor-Loop and it works, but then is a temporal variable and I can not use it after the parfor-Loop.
Could you please help me to define V as a Sliced output Variable? V is the variable that I have to work with after the parfor-Loop.
Thanks in advance.
1 V=zeros(numel(Ppara),numel(Pperp),numel(tau));%
2
3 parfor j_G=1:numel(Ppara)*numel(Pperp)
4 % rest of the code
5
6 V(JG(j_G,1),JG(j_G,2),: )=sum(Ap_tau);
7 end
The matrix JG is:
JG =
1 1
1 2
2 1
2 2
3 1
3 2
4 1
4 2

Answers (1)

Matt J
Matt J on 9 Apr 2022
Edited: Matt J on 9 Apr 2022
N=numel(Pperp); M=numel(Ppara);
V=zeros(N*M,numel(tau));%
parfor j_G=1:N*M
%rest of code
V(j_G, : )=sum(Ap_tau);
end
V=permute( reshape(V,N,M,[]) ,[2,1,3]);

2 Comments

Hi @Matt J,
Thanks for helping me.
I have tried your solution, but the error remains, exactly as before.
I would appreciate if, based on your experience, you could help me with another suggestion.
Thanks again.
You're probably running your old script by mistake. There's no way it's the same.

Sign in to comment.

Categories

Products

Release

R2019b

Tags

Asked:

on 9 Apr 2022

Commented:

on 10 Apr 2022

Community Treasure Hunt

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

Start Hunting!