首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >转换MatLab代码-混淆

转换MatLab代码-混淆
EN

Stack Overflow用户
提问于 2012-08-17 00:41:58
回答 1查看 274关注 0票数 0

基本上,我有最后一段代码要从MatLab转换为C++。

该函数接受2D向量,然后根据2个条件检查2D向量的元素,如果不匹配,它将删除块。但是我搞不懂MatLab中的代码想要返回什么,是2D还是1D向量?代码如下:

代码语言:javascript
复制
function f = strip(blocks, sumthresh, zerocrossthresh)

% This function removes leading and trailing blocks that do 
% not contain sufficient energy or frequency to warrent consideration.
% Total energy is measured by summing the entire vector.
% Frequency is measured by counting the number of times 0 is crossed.
% The parameters sumthresh and zerocrossthrech are the thresholds,
% averaged across each sample, above which consideration is warrented.

% A good sumthresh would be 0.035
% A good zerocrossthresh would be 0.060

len = length(blocks);
n = sum(size(blocks)) - len;
min = n+1;
max = 0;
sumthreshtotal = len * sumthresh;
zerocrossthreshtotal = len * zerocrossthresh;
for i = 1:n
currsum = sum(abs(blocks(i,1:len)));
currzerocross = zerocross(blocks(i,1:len));
if or((currsum > sumthreshtotal),(currzerocross > zerocrossthreshtotal))
if i < min
  min = i;
end
if i > max;
  max = i;
  end
end
end

% Uncomment these lines to see the min and max selected
% max
% min

 if max > min
   f = blocks(min:max,1:len);
 else
 f = zeros(0,0);
end

或者,与其返回另一个向量(无论是1D还是2D),实际上发送向量的内存位置并从中删除块会更好吗?举个例子..

代码语言:javascript
复制
for(unsigned i=0; (i < theBlocks.size()); i++)
{
  for(unsigned j=0; (j < theBlocks[i].size()); j++)
  {
      // handle theBlocks[i][kj] .... 
  }
}

另外,我不理解这句话:

代码语言:javascript
复制
currsum = sum(abs(blocks(i,1:len)));

基本上:(i,1:len)

有什么想法吗?谢谢:)

EN

回答 1

Stack Overflow用户

发布于 2012-08-17 01:35:14

blocks(i,1:len)告诉数组,它想要从blocks[i][1 to the end]转过来。因此,如果它是一个3x3数组,它会这样做:

代码语言:javascript
复制
blocks[i][1]
blocks[i][2]
blocks[i][3]
.
.
.
blocks[i][end]

然后取矩阵内容的绝对值,并将它们相加。它返回一个x矩阵,但长度要么是0x0,要么是(max)X(len)。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11991814

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档