预先分配.NET数组的矩阵 [英] Preallocating a Matrix of .NET Arrays

查看:159
本文介绍了预先分配.NET数组的矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Matlab为实验设置数据采集过程,函数 ain.DAQbufferGet 是从我们的硬件中读取数据的内容。它包含一系列数据点,如 [ - 200,-160,10,50,-20,40,170,160,-200 ...等]



问题在于DAQbufferGet的输出是一个 1x1 System.Int16 []



这样的输出也可以通过使用

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

这里 50000 就是一个例子编号

我想将DAQbufferGet的输出存储在一个矩阵中,而不必将其转换为不同的数据类型,并能够稍后绘制它(循环外部),如下所示:

$ p $ data = int16(零(10,50000));

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

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

我很难做类似于 1x1 System.Int16 [] 数据类型

我该怎么做?



特别预先分配一个.NET数组的矩阵,这个数组可以在以上描述的for循环中写入。 看起来,将.NET数组存储在一个单元格中意味着您可以稍后解压缩并索引。

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

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

data {i}返回一个可以转换为另一个数据的.NET数组键入并绘制

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.

解决方案

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

这篇关于预先分配.NET数组的矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆