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

3 vues (au cours des 30 derniers jours)
Charlie Bright
Charlie Bright le 10 Août 2022
Réponse apportée : Tejas le 26 Déc 2024
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.

Réponses (1)

Tejas
Tejas le 26 Déc 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

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by