C++ 中的矩阵生成
我有以下代码:
for (int w=0; w<10; w++)
{
//some lines of code
unsigned long num = x.to_ulong();
cout << "Decimal form is: " << num << endl;
}
现在我想要的是,制作一个矩阵,该矩阵将具有这些 num 值,逐列。例如,matrix[i][j]
,其中 i
是从“0 到 15”,“j”是从“0 到 15”,如下所示出色地。我希望他们像,matrix[0][0]
,然后matrix[0][1]
,matrix[0][2]
代码>等等,比如:
for(int i=0; i<=15; i++)
{
for(int j=0; j<=15; j++)
matrix[i][j] = num //here is problem, value of "num" what shall i write instead of it?
}
I have the following code:
for (int w=0; w<10; w++)
{
//some lines of code
unsigned long num = x.to_ulong();
cout << "Decimal form is: " << num << endl;
}
Now what I want is, to make a matrix which will have these values of num, column wise. For example, matrix[i][j]
, where i
is from, let's say "0 to 15", and "j" is from "0 to 15" as well. I want them to put like, matrix[0][0]
, then matrix[0][1]
, matrix[0][2]
and so on, something like:
for(int i=0; i<=15; i++)
{
for(int j=0; j<=15; j++)
matrix[i][j] = num //here is problem, value of "num" what shall i write instead of it?
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一些伪代码。
注意:您必须进行一些边界检查(例如,如果数字多于 15 * 15,则递增迭代器
row
将导致垃圾...等)编辑:像普通数组一样显示、迭代,例如:
Here is some pseudo code..
NOTES: you'll have to do some bounds checking (for example if there are more numbers than 15 * 15, the incrementing the iterator
row
will lead to crap... etc.)EDIT: to display, iterate through like a normal array, for example:
标准“使用Boost”答案:
如果您只需要一个二维数组,请查看Boost.MultiArray。
如果您需要进行线性代数,请查看 Boost .uBlas。
Standard "use Boost" answer:
If you just need a two-dimensional array, check out Boost.MultiArray.
If you need to do linear algebra, check out Boost.uBlas.