Alternative ways to slice/manage data using PARFOR
Mostra commenti meno recenti
Hello,
I am a beginner MATLAB user, hence probably my question seems simple but I have spent quite a bit of time trying to find solutions for this.
I essentially have a large number of variables, or arrays of data (over 130) that are populated by data generated in a parfor loop (I am keen to use parfor because the script will run through quite large amounts of data, and is significantly more efficient).
As I have said it is a large number of arrays, and the way I am creating the emtpty arrays, and then populating them and managing them later in the scrip is just very line-consuming and does not look good to me.
The script (this is a very simplified example to illustrate the problem) looks like this:
Data = rand(1,1000);
A = nan(1,1000);
B = nan(1,1000);
C = nan(1,1000);
D = nan(1,1000);
E = nan(1,1000);
% (in my cript there is 130 variables )
parfor i = 1:1000
a = (Data(1,i) * 526^3)/5;
b = (Data(1,i) * 255^2)/6;
c = a*b;
d = a/b;
e = a^b;
A(1,i) = a;
B(1,i) = b;
C(1,i) = c;
D(1,i) = d;
E(1,i) = e;
end
But ideally I would like to do something like this:
Data = rand(1,1000);
SolCell = {'A'; 'B'; 'C'; 'D'; 'E'};
for i = 1: size(SolCell,1)
SolCell{i,2} = nan(1,1000);
end
parfor i = 1:1000
a = (Data(1,i) * 526^3)/5;
b = (Data(1,i) * 255^2)/6;
c = a*b;
d = a/b;
e = a^b;
SolCell{1,2}(i) = a;
SolCell{2,2}(i) = b;
SolCell{3,2}(i) = c;
SolCell{4,2}(i) = d;
SolCell{5,2}(i) = e;
end
But this results in a 'variable classification' error, as parfor does not like structures or cells.
Thank you very much in advance for your help!
Carlos
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Parallel for-Loops (parfor) in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!