i am trying to get emg and force data simultaneously using parallel computing tool box but i am unable to read the data???

i am using the below code
if matlabpool('size') == 0
matlabpool open local 2
data1=zeros([122880,2]);
data2=zeros([37000,1]);
spmd
switch labindex
case 1
s = daq.createSession('ni');
s.addAnalogInputChannel('cDAQ2Mod1', 0, 'Voltage');
s.addAnalogInputChannel('cDAQ2Mod1', 1, 'Voltage');
s.Rate = 2048
s.DurationInSeconds = 60;
labBarrier
[data1,time] = s.startForeground;
case 2
delete(instrfindall);
s = serial ( 'COM5', 'BaudRate', 115200);
set(s, 'Timeout',60);
s.InputBufferSize =37000;
labBarrier
fopen(s);
data2=fread(s);
end
end
end
matlabpool close
my workspace is containing data in composite form
data1 composite
data2 composite
is there any way to solve this problem???

5 Comments

Values returning from the body of an spmd statement are converted to Composite objects on the MATLAB client. A Composite object contains references to the values stored on the remote MATLAB workers, and those values can be retrieved using cell-array indexing. The actual data on the workers remains available on the workers for subsequent spmd execution, so long as the Composite exists on the client and the parallel pool remains open.
What is the problem? You can access the elements of data1 and data2 using indexing, like so
>> data1{1} % get a single element
>> data2(:) % get all elements as a cell array
data1(1);
Error using Composite/subsref (line 23)
Either the Composite has been saved and then loaded, or
the matlabpool for that Composite has been closed.
Error using Composite/subsref (line 48) An invalid indexing request was made
Error in sync (line 44) E=data1(:);
Caused by: Error using Composite/subsref>iCheckValuesExist (line 86) The Composite has no value on the following lab(s): 2 .

Sign in to comment.

 Accepted Answer

The data contained within a Composite is retained on the workers. Therefore if you close the pool, the data goes away. So, you simply need to avoid closing the pool until you've got the data from the workers. One way to do this would be:
data1 = data1(:);
data2 = data2(:);
matlabpool close
Or, you could simply leave the matlabpool open.

7 Comments

here i am changing the above lines [data1,time] = s.startForeground;
data2=fread(s); to
[data1(:)] = s.startForeground;
[data2(:)]=fread(s);
but in the workspace i am not able to see the data and i am not using matlabpool close
data1(:)
ans =
[122880x2 double]
[122880x2 double]
>> data2(:)
ans =
[37000x1 double]
[37000x1 double]
That sounds like you got the results out, each one being a 2 x 1 cell array each entry of which contains a 122880x2 matrix ?
if matlabpool('size') == 0 matlabpool open local 2
spmd
switch labindex
case 1
s = daq.createSession('ni');
s.addAnalogInputChannel('cDAQ2Mod1', 0, 'Voltage');
s.addAnalogInputChannel('cDAQ2Mod1', 1, 'Voltage');
s.Rate = 2048
s.DurationInSeconds = 60;
labBarrier
data1 = s.startForeground;
case 2
delete(instrfindall);
s = serial ( 'COM5', 'BaudRate', 115200);
set(s, 'Timeout',60);
s.InputBufferSize =37000;
labBarrier
fopen(s);
data2=fread(s);
end
end
E1=data1(:,1);
E2=data1(:,2);
F=data2(:);
celldisp(F);
end
matlabpool close
Caused by: Error using Composite/subsref>iCheckValuesExist (line 86) The Composite has no value on the following lab(s): 2 .
Assign each variable on each of the labs, even it is just assigning [] to it.
data1 = s.startForeground;
data2 = [];
...
i am able to get data using data1=data1{:,1}; data2=data2{:,2}; thank you @walter roberson @edric ellis

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!