Use structures in a parfor loop

1 view (last 30 days)
Davide Mastrodicasa
Davide Mastrodicasa on 9 Jan 2020
Hello everyone.
I have a problem using structures in a parfor loop. I would like to save my output of the parfor loop in a structure called "Output".
if strcmpi(String.Frequency_Filter,'Yes')
WaitMessage = parfor_wait(NN,'Waitbar',true);
if strcmpi(String.Output_type, 'displacement') || strcmpi(String.Differentiation_Variable, 'Frequency')
parfor ii=1:NN
if strcmpi(String.DOF,'X')
Output.u_G_Interp(ii,:)=bandpass(Output.u_G_Interp(ii,:),B,fs);
elseif strcmpi(String.DOF,'Y')
Output.v_G_Interp(ii,:)=bandpass(Output.v_G_Interp(ii,:),B,fs);
elseif strcmpi(String.DOF,'Z')
Output.w_G_Interp(ii,:)=bandpass(Output.w_G_Interp(ii,:),B,fs);
elseif strcmpi(String.DOF,'XYZ')
Output.u_G_Interp(ii,:)=bandpass(Output.u_G_Interp(ii,:),B,fs); Output.v_G_Interp(ii,:)=bandpass(Output.v_G_Interp(ii,:),B,fs); w_G_Interp(ii,:)=bandpass(Output.w_G_Interp(ii,:),B,fs);
end
WaitMessage.Send;
end
end
end
Unfortunately (like in the figure below) it is not possible to use directly structures in a parfor loop and I cannot use a temporary variable inside the parfor loop and after writing it inside my structure because the if that i will use in the parfor loop depends on a defind String in the main of my code and not all the variables exists. For example if i have String.DOF='Z' just the w_G_Interp variable exists and I get an error in writing the u_G_Interp variable beacause it doesn't exist.
if strcmpi(String.Frequency_Filter,'Yes')
WaitMessage = parfor_wait(NN,'Waitbar',true);
if strcmpi(String.Output_type, 'displacement') || strcmpi(String.Differentiation_Variable, 'Frequency')
parfor ii=1:NN
if strcmpi(String.DOF,'X')
u_G_Interp(ii,:)=bandpass(Output.u_G_Interp(ii,:),B,fs);
elseif strcmpi(String.DOF,'Y')
v_G_Interp(ii,:)=bandpass(Output.v_G_Interp(ii,:),B,fs);
elseif strcmpi(String.DOF,'Z')
w_G_Interp(ii,:)=bandpass(Output.w_G_Interp(ii,:),B,fs);
elseif strcmpi(String.DOF,'XYZ')
u_G_Interp(ii,:)=bandpass(u_G_Interp(ii,:),B,fs); v_G_Interp(ii,:)=bandpass(Output.v_G_Interp(ii,:),B,fs); w_G_Interp(ii,:)=bandpass(Output.w_G_Interp(ii,:),B,fs);
end
WaitMessage.Send;
end
end
end
Output.u_G_Interp=u_G_Interp;
Output.v_G_Interp=v_G_Interp;
Output.w_G_Interp=w_G_Interp;
I hope the question is clear and thank you in advance for the reply.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!