Trouble getting data outside of parfor loop
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
John Doe
am 27 Aug. 2013
Beantwortet: John Doe
am 28 Okt. 2013
Hello, I have a process that needs to be applied to a 90 trials of an 11 electrode signal. The result of each trial is in the form of 11 different matrices of a number of rows that varies between trials (no greater than 12). I'm having trouble getting those matrices stored without matlab saying it can't be done whilst using parfor.
I create giant matrices of zeros outside the loop that has enough space for the max possible number of rows. Then inside the loop I try and pass the data to giantmatrix(rowNumber:rowNumber + row length of data, :).
clear all
matlabpool;
load MIdata25;
fs = 160;
numberElectrodes = 11;
Left1 = zeros(15*length(squeeze(thinkLeft(1, :, 1))), 1312);
Left2 = zeros(15*length(squeeze(thinkLeft(1, :, 1))), 1312);
Left3 = zeros(15*length(squeeze(thinkLeft(1, :, 1))), 1312);
Left4 = zeros(15*length(squeeze(thinkLeft(1, :, 1))), 1312);
Left5 = zeros(15*length(squeeze(thinkLeft(1, :, 1))), 1312);
Left6 = zeros(15*length(squeeze(thinkLeft(1, :, 1))), 1312);
Left7 = zeros(15*length(squeeze(thinkLeft(1, :, 1))), 1312);
Left8 = zeros(15*length(squeeze(thinkLeft(1, :, 1))), 1312);
Left9 = zeros(15*length(squeeze(thinkLeft(1, :, 1))), 1312);
Left10 = zeros(15*length(squeeze(thinkLeft(1, :, 1))), 1312);
Left11 = zeros(15*length(squeeze(thinkLeft(1, :, 1))), 1312);
parfor currentTrial = 1:length(squeeze(thinkLeft(1, :, 1)))
currentTrial
chanNum = 0;
signalL=[];
signalTotal=[];
for currentElectrode = [2 6 8 9 11 13 14 16 20 41 42]
%matrix indexing stuff
signalTotal = [signalTotal; signalL3'];
end
x = %process applied to signalTotal
for currentElectrode = 1:11
xxl = zeros(numberElectrodes, length(signalL(1, :)));
for imfNo = 1:length(squeeze(x(1, :, 1)))
%matrix re-indexing stuff
end
if currentElectrode == 1
Left1(((currentTrial-1)*15)+1:((currentTrial-1)*15)+length(xxl(:, 1)), :) = xxl;
elseif currentElectrode == 2
Left2(((currentTrial-1)*15)+1:((currentTrial-1)*15)+length(xxl(:, 1)), :) = xxl;
elseif currentElectrode == 3
Left3(((currentTrial-1)*15)+1:((currentTrial-1)*15)+length(xxl(:, 1)), :) = xxl;
elseif currentElectrode == 4
Left4(((currentTrial-1)*15)+1:((currentTrial-1)*15)+length(xxl(:, 1)), :) = xxl;
elseif currentElectrode == 5
Left5(((currentTrial-1)*15)+1:((currentTrial-1)*15)+length(xxl(:, 1)), :) = xxl;
elseif currentElectrode == 6
Left6(((currentTrial-1)*15)+1:((currentTrial-1)*15)+length(xxl(:, 1)), :) = xxl;
elseif currentElectrode == 7
Left7(((currentTrial-1)*15)+1:((currentTrial-1)*15)+length(xxl(:, 1)), :) = xxl;
elseif currentElectrode == 8
Left8(((currentTrial-1)*15)+1:((currentTrial-1)*15)+length(xxl(:, 1)), :) = xxl;
elseif currentElectrode == 9
Left9(((currentTrial-1)*15)+1:((currentTrial-1)*15)+length(xxl(:, 1)), :) = xxl;
elseif currentElectrode == 10
Left10(((currentTrial-1)*15)+1:((currentTrial-1)*15)+length(xxl(:, 1)), :) = xxl;
elseif currentElectrode == 11
Left11(((currentTrial-1)*15)+1:((currentTrial-1)*15)+length(xxl(:, 1)), :) = xxl;
end
end
midpointL(currentTrial, :) = length(xxl(:, 1));
end
With matlab showing problems with Left1-9, though it seems fine with midpointL.
1 Kommentar
Walter Roberson
am 27 Aug. 2013
Try replacing the length(xx1(:,1)) with numberElectrodes since you built xx1 with numberElectrodes as the first dimension.
Akzeptierte Antwort
Weitere Antworten (1)
Matt J
am 27 Aug. 2013
Bearbeitet: Matt J
am 28 Aug. 2013
I create giant matrices of zeros outside the loop that has enough space for the max possible number of rows. Then inside the loop I try and pass the data to giantmatrix.
A better idea would probably be to dispense with Left1...9 and instead store the results (of different sizes) in a 90x11 cell array. Then combine them after the loops end as needed.
N=length(squeeze(thinkLeft(1, :, 1)));
LoopData=cell(N, 11);
parfor currentTrial = 1:N
for currentElectrode = 1:11
xxl = ...;
LoopData{currentTrial,currentElectrode}=xxl;
end
end
Now you can combine all the different xxl in LoopData using cell2mat() or similar...
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing 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!