简体   繁体   English

在C ++中访问矩阵的多个元素

[英]Accessing multiple elements of a matrix in C++

I have following Matlab code: 我有以下Matlab代码:

A = rand(4); % just for an example
B = A(1:3,1:2); 

Thus B will be a 3x2 matrix and will contain elements of A starting from first row to third row and first column to second column. 因此,B将是一个3x2矩阵,并将包含A的元素,从第一行到第三行,从第一列到第二列。 I could certainly do this in C++ with a for loop, but is there an easier way (like Matlab) to do this? 我当然可以在C ++中使用for循环来执行此操作,但是有没有更简单的方法(例如Matlab)来执行此操作?

You are looking for something like the Armadillo library 您正在寻找Armadillo库之类的东西

Check here the conversion table between Matlab/Octave and C++ 在此处检查Matlab / Octave与C ++之间的转换表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM