如何从犰狳中的函数返回多个值?
我是 c++ 和犰狳的新手。我编写了一个函数,如下所示:
mat solver(mat charge)
{
mat x = regspace(0, mesh_num - 1);
mat xx = reshape(x, 1, mesh_num);
mat xxx = repmat(xx, mesh_num, 1);
mat y = regspace(0, mesh_num - 1);
mat yy = reshape(y, mesh_num, 1);
mat yyy = repmat(yy, 1, mesh_num);
mat green_func = -0.5 * log(square(step_xc * xxx) + square(step_yc * yyy));
green_func(0, 0) = 0;
mat temp_1 = fliplr(green_func);
mat temp_2 = temp_1.cols(0, mesh_num - 2);
mat temp_3 = flipud(green_func);
mat temp_4 = temp_3.rows(0, mesh_num - 2);
mat temp_5 = fliplr(temp_4);
mat temp_6 = temp_5.cols(0, mesh_num - 2);
mat temp_7 = join_horiz(temp_6, temp_4);
mat temp_8 = join_horiz(temp_2, green_func);
mat green_fun_expand = join_vert(temp_7, temp_8);
return green_fun_expand;
}
我想返回多个矩阵,例如 green_func_expand 和 temp_8。如何实现这一目标?
I'm new to c++ and Armadillo. I've written a function as follows:
mat solver(mat charge)
{
mat x = regspace(0, mesh_num - 1);
mat xx = reshape(x, 1, mesh_num);
mat xxx = repmat(xx, mesh_num, 1);
mat y = regspace(0, mesh_num - 1);
mat yy = reshape(y, mesh_num, 1);
mat yyy = repmat(yy, 1, mesh_num);
mat green_func = -0.5 * log(square(step_xc * xxx) + square(step_yc * yyy));
green_func(0, 0) = 0;
mat temp_1 = fliplr(green_func);
mat temp_2 = temp_1.cols(0, mesh_num - 2);
mat temp_3 = flipud(green_func);
mat temp_4 = temp_3.rows(0, mesh_num - 2);
mat temp_5 = fliplr(temp_4);
mat temp_6 = temp_5.cols(0, mesh_num - 2);
mat temp_7 = join_horiz(temp_6, temp_4);
mat temp_8 = join_horiz(temp_2, green_func);
mat green_fun_expand = join_vert(temp_7, temp_8);
return green_fun_expand;
}
I'd like to return more-than-one matrix, e.g. green_func_expand and temp_8. How to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在接收这个时使用Tuple STL
,尝试
然后你可以直接使用ret1和ret2
或者,你可以使用一个类并添加你想要返回的任何内容作为类变量,在你的函数中创建类的对象,填充变量并返回对象
use a Tuple STL
while recieving this , try
then you can directly use ret1 and ret2
Alternatively , you can use a class and add whatever you want to return as class variables, create object of class inside your function, populate the variables and return the object