Use structures in a parfor loop

1 回表示 (過去 30 日間)
Davide Mastrodicasa
Davide Mastrodicasa 2020 年 1 月 9 日
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.

回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by