有没有什么办法可以总结矩阵中每组三行的列值?
我可以手动方式将三行加起来.
例如
% matrix is the one I wanna store the new data.
% data is the original dataset.
matrix(1,1:end) = sum(data(1:3, 1:end))
matrix(2,1:end) = sum(data(4:6, 1:end))
...
Run Code Online (Sandbox Code Playgroud)
但是如果数据集很大,那就不行了.
有没有办法在没有循环的情况下自动执行此操作?
'' [ 2281] [ 2520] [8]
'' [] [] ''
Run Code Online (Sandbox Code Playgroud)
像我的cell数组中的上述数据一样.如何确定第二行无效?我试过isempty(),但结果不是最佳的.
例如,我有一个 4*5*6 的 3D 矩阵。我想把它分成6个二维矩阵。目的是对这些二维矩阵进行数据运算并得到结果。尝试了 row()、rowRange(),我遇到了错误。目前没有任何线索。有人提出更好的想法吗?谢谢~
我不认为自己掌握了shared_ptr.
示例代码:
shared_ptr<ofstream> logger;
int main(){
logger = make_shared<ofstream>(new ofstream("ttt.txt"));
*logger <<"s";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
错误1错误C2664:'std :: basic_ofstream <_Elem,_Traits> :: basic_ofstream(const char*,std :: ios_base :: openmode,int)':无法从'std :: basic_ofstream <_Elem,_Traits>转换参数1 'to'conc char*'c:\ program files(x86)\ microsoft visual studio 10.0\vc\include\xxshared 13
编辑:
[
In the mean time, if I wanna close the ofstream while some crashes happened.
How can I do it?
I mean if shared_ptr release the memory without closing the file.
There would be problems.
]
Run Code Online (Sandbox Code Playgroud)
我不知道如何实现这一目标.或许这根本就是胡说八道.希望任何人都可以提出一个想法或指出我理解中缺乏的一部分shared_ptr.
我正在努力使用opencv将3D矩阵的元素归零.我可以将2D矩阵中的所有元素归零,如下所示:
meta = new Mat(Mat::zeros(cluster,3,CV_32S));
Run Code Online (Sandbox Code Playgroud)
我尝试使用类似的方法在3D矩阵中初始化0的元素,它失败了.
block = new Mat(Mat::zeros(3,dim,CV_32F));
Run Code Online (Sandbox Code Playgroud)
错误信息:
1>MatrixOp.obj : error LNK2019: unresolved external symbol "public: static class cv::MatExpr __cdecl cv::Mat::zeros(int,int const *,int)" (?zeros@Mat@cv@@SA?AVMatExpr@2@HPBHH@Z) referenced in function "public: __thiscall MatrixOp::MatrixOp(char *)" (??0MatrixOp@@QAE@PAD@Z)
Run Code Online (Sandbox Code Playgroud)
我有一个初始化矩阵的最后一种方法.遍历矩阵并设置元素值0.但它看起来很省力.
for(int i=0;i<value_num;i++)
for(int j=0;j<frame_no;j++)
for(int k=0;k<cluster;k++)
block->at<float>(i,j,k) = 0;
Run Code Online (Sandbox Code Playgroud)
谁能给我一个更好的想法?谢谢.