Parallel Processing code question, with error Subscripted assignment between dissimilar structures
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bart
am 27 Mai 2015
Kommentiert: Carey Smith
am 8 Mai 2017
I am trying to become familiar with the parallel toolbox and wrote what I think is a simple script that is failing and I don't understand why. I have included the code below.
clear all
close all
dataSetSize = 1024;
for x = 1:4:dataSetSize
Data(x).dataSet = rand(128,256);
Data(x+1).dataSet = rand(128,512);
Data(x+2).dataSet = rand(64,128);
Data(x+3).dataSet = rand(32,64);
end
parpool(4);
parfor x=1:dataSetSize
Data(x).plotData = 20*log10(abs(fft(Data(x).dataSet)));
end
I get the error
Error using parallelTest (line 15)
Subscripted assignment between dissimilar structures.
Line 15 is the line of the parfor loop. When I execute this as a regular loop it executes fine. I don't see any dependencies and think this should be able to run in parallel.
Any help would be greatly appreciated.
Thanks
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 27 Mai 2015
You need to initialize the PlotData field before the loop. Even if you initialize it to [] that would be fine. In your code, the result of the parfor is a structure with a different set of fields than the original, and there are problems copying the data back because of that. Don't create new struct fields inside a parfor.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!