![]() |
如何将值附加到2D数组?
我是MATLAB的新手,我无法从文档中了解这一点。
function GotData(sender, args) interval = args.DataBlock.TimeIntervalInMicroseconds; doubles = args.DataBlock.AsDoubleArray(); x = 0; complexCount = length(double(doubles))/2; DATA = zeros(complexCount); for index = 1:(complexCount-1) realnum = doubles(2 * index); imagnum = 1i * doubles(2 * index + 1); complex = realnum + imagnum; x = x + interval; DATA(index) = [x complex]; end disp(DATA) end 我从.NET程序集中触发的事件中获得了一个双打数组。我将数组拆分为每个偶数项(在基于1的数组中)是一个虚数,每个奇数项都是实数。然后,我创建一个复数及其间隔的两个项目数组。然后,我想将此1D数组附加到2D数组。我怎么做? 目前,我遇到一个错误: In an assignment A(I) = B, the number of elements in B and I must be the same. 。我该怎么办? interval为1,但可以调整。 [B]回答:[/B] 如果您希望DATA是二维数组,则需要对其进行初始化并按如下方式对其进行索引: % ...(your code)... DATA = zeros(complexCount-1, 2); % Initialize DATA to an N-by-2 matrix % ...(your code)... DATA(index, :) = [x complex]; % Add the array to a row of DATA % ...(your code)... 您可以查看这些MathWorks文档链接,以获取有关在MATLAB中[URL="https://www.mathworks.com/help/matlab/math/creating-and-concatenating-matrices.html"]创建矩阵[/URL]和[URL="https://www.mathworks.com/help/matlab/math/matrix-indexing.html"]矩阵索引的[/URL]更多信息。 [url=https://stackoverflow.com/questions/3102809]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 01:07。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.