0

I'm using Matlab to setup the data acquisition process for an experiment, the function ain.DAQbufferGet is what reads the data from our hardware. It holds a series of data points such as [-200,-160,10,50,-20,40,170,160,-200... etc].

The problem is that the output of DAQbufferGet is a 1x1 System.Int16[]

Such an output can also be created by using

`NET.createArray('System.Int16', 50000)` 

Here 50000 is just an example number

I want to store the output of DAQbufferGet in a matrix without having to convert it to a different data type, and to be able to plot it later (outside the loop), as shown here:

data = int16(zeros(10, 50000));

for k = 1:10
    data(k,:) = int16(zeros(1,50000));
end

for i = 1:10
    data(i,:) = int16(ain.DAQbufferGet());
end

I have had difficulty doing something similar with the 1x1 System.Int16[] data type

How would I do this?

Specifically preallocate a matrix of .NET arrays which can later be written to in the for loop described above.

JCW
  • 43
  • 7
  • 1
    In which environment are you going to use and plot your data after acquisition ? If it is in Matlab there is little advantage in keeping the `.net` data type for long. I would convert the output of `DAQbufferGet` directly on reception and store it in Matlab in the most convenient data type _built-in_ in Matlab. – Hoki Sep 04 '17 at 11:41
  • Yes it will be in Matlab. Ideally I would convert to another data type outside of the loop. The loop needs to just acquire and store the data as quickly as possible, and converting just makes it too slow – JCW Sep 04 '17 at 12:43
  • 1
    You cannot use the `.net` arrays this way. The `.net` arrays supported by Matlab **DO NOT** support the colon operator. They only support **scalar** indexing. It means you cannot use this type of assignment `data(:,i)=...`. You have to handle them in a loop, element by element, the classic `.net` way: `for k=1:n;data(k,i)=...;end;` etc... – Hoki Sep 04 '17 at 14:32
  • This does not seem to work either, if I try `data(i) = NET.createArray('System.Int16', n)`. I get the error `No method '()' with matching signature found for class 'System.Int16[]'.`. I have created a more specific question here: [Storing Multiple .NET Arrays (Matlab)](https://stackoverflow.com/questions/46052684/storing-multiple-net-arrays-matlab) – JCW Sep 05 '17 at 10:29

1 Answers1

1

It seems that storing the .NET array in a cell means you can later extract it and index as such

for k = 1:10
data{k} = NET.createArray('System.Int16', 50000);
end

for i = 1:10
data{i} = ain.DAQbufferGet();
end

data{i} returns a .NET array which can be converted to another data type and plotted

JCW
  • 43
  • 7