How can I convert a .NET array of instrument data into a row-and-column Matlab array?

2 visualizaciones (últimos 30 días)
I would appreciate some pointers on understanding how to extract instrument data from separate channels from scaledData in the following and put them into the typical row-and-column Matlab array:
scaledData = NET.createArray('System.Double', sectionLength*sectionCount*channelCount);
errorCode = waveformAiCtrl.GetData(sectionLength*sectionCount*channelCount,scaledData,-1); % where -1 means wait for buffer to fill up.
Thank you.

Respuestas (1)

Tejas
Tejas el 26 de Dic. de 2024
Hello Charlie,
To extract data from an object created with 'NET.createArray', the 'Get' method can be utilized. For more information on methods associated with this object, refer to this documentation: https://www.mathworks.com/help/matlab/matlab_external/calling-net-methods.html .
Once the data is extracted, memory pre-allocation and array indexing can be used to efficiently store the data in a MATLAB array.
Here is an example for this approach:
  • Generate sample data.
dim1 = 10;
dim2 = 5;
dim3 = 3;
scaleData = NET.createArray('System.Double', [dim1, dim2, dim3]);
for i = 0:(dim1-1)
for j = 0:(dim2-1)
for k = 0:(dim3-1)
randomValue = rand() * 100;
scaleData.Set(i, j, k, randomValue);
end
end
end
  • Pre-allocate memory for the MATLAB array where the data will be stored.
matlabArray = zeros(dim1, dim2, dim3);
  • Use the 'Get' method to extract values from 'scaleData' and store them in a MATLAB array.
for i = 0:(dim1-1)
for j = 0:(dim2-1)
for k = 0:(dim3-1)
value = scaleData.Get(i, j, k);
matlabArray(i+1, j+1, k+1) = value;
end
end
end

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by