**
armadillo矩阵在VS2013调试中的可视化显示方法
**
这个问题耗时了一天,总算解决了。armadillo是一个优秀的开源矩阵运算库,可将matlab仿真代码移植到VS C++ 代码中去。如何在VS调试中显示armadillo的值呢?
第一步,右键项目---添加---新建项,添加一个natvis文件,文件名为 armadillos.natvis,
1.新建natvis文件
armadillos.natvis文件内容为如下:
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="arma::Col<*>">
<DisplayString>{{ Size = {n_elem} }}</DisplayString>
<Expand>
<Item Name="[size]">n_elem</Item>
<ArrayItems>
<Size>n_elem </Size>
<ValuePointer>mem</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<Type Name="arma::Mat<*>">
<DisplayString>{{ {n_rows} x {n_cols} = {n_elem} }}</DisplayString>
<Expand>
<IndexListItems>
<Size>n_cols</Size>
<ValueNode >
mem+($i*n_rows),[n_rows]
</ValueNode>
</IndexListItems>
</Expand>
</Type>
<Type Name="arma::subview_col<*>">
<DisplayString>{{ {n_rows} }}</DisplayString>
<Expand>
<ArrayItems>
<Size>n_rows</Size>
<ValuePointer>colmem</ValuePointer>
</ArrayItems>
</Expand>
</Type>
</AutoVisualizer>
2.选择调试—选项和设置—调试—常规,取消勾选“在变量窗口中显示对象的原始结构”,如下:
3.测试,新建console项目,主函数即断点位置如下:
// armadillo_mytest.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <armadillo>
# include <opencv2/core/core.hpp>
# include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace arma;
//using namespace cv;
template<class Matrix>
void print_matrix(Matrix matrix){
matrix.print(std::cout);
}
int main()
{
mat A = randu<mat>(5, 5);
mat B = randu<mat>(5, 5);
cx_mat C = zeros<cx_mat>(5, 5);
C.set_real(A);
C.set_imag(B);
C.print("signal");
cx_mat D = fft(C);
cx_mat E = ifft(D);
arma::mat matrix = arma::randu(10, 10);
D.print("fft:");
E.print("ifft:");
return 0;
}