试图创建矩阵图,但出现了问题
Trying to create a matrix plot, but something is wrong
现在,该程序的主要目标是创建一个121x61矩阵,重置它,并绘制两条表示绘图平面的线。然而,由于某种原因,这个程序确实为y线创建了绘图,但它以某种方式再次将其复制到矩阵中的几个位置(不过它跳过了一个值)。绘图时必须将0替换为1。这是代码:
#include <iostream>
#include <cmath>
#define rd 57.2957795
#define k 0.05
using namespace std;
void rmat(int matrix[121][61])
{
for (int i=0;i<121;i++)
{
for(int j=0;j<61;j++)
{
matrix[i][j] = 0;
}
}
}
void matrix_print(int matrix[121][61])
{
for( int y = 0; y < 61 ; y++ )
{
for( int x = 0; x < 121; x++ )
{
cout << matrix[y][x];
}
cout << "n";
}
}
void mplot(int matrix[121][61])
{
for( int y = 0; y < 61 ; y++ )
matrix[y][0] = 1;
}
int main(void)
{
int matrix[121][61];
int i,x=0;
double y = 0;
double temp;
rmat(matrix);
system("mode con: cols=200 lines=200");
/* for( x ; x < 180 ; x = x + 4 )
{
temp = cos(double(x) / rd);
}
*/
mplot(matrix);
matrix_print(matrix);
system("pause");
}
您的矩阵索引在几个地方都是错误的:第一个索引从0到120,第二个索引从零到60,而不是相反。
以下是这样一个错误的例子:
for( int y = 0; y < 61 ; y++ )
{
for( int x = 0; x < 121; x++ )
{
cout << matrix[y][x];
相关文章:
- 使用C++在Qt3D中创建多个视口时出现问题
- 基本的 c++ 问题:如果我在函数中创建某些内容并返回它会发生什么?
- 在解决链表问题时创建一个额外的节点是一个好习惯吗?
- 在 c++ 中创建和访问 4D 向量时出现问题
- 关于在 c++ 中创建公式的问题
- 在C ++ ASIO中,如何为HTTP或HTTPS创建相同的套接字对象(接口/抽象问题?
- 在另一个类中创建类实例时出现问题
- 为什么我的类电影在创建电影实例时遇到问题?
- 我正在尝试创建一个 C++ 贪吃蛇游戏,但我似乎无法绘制第二个高度边框,我该如何解决这个问题?
- 创建堆栈时出现问题!(街机游戏)
- 使用暂停按钮ARDUINO创建灯光序列时出现问题
- 我的代码在创建楼梯图案时出了什么问题
- 创建二进制文件时出现问题
- 在 QLayout 中创建和删除自定义 QWidgets 时出现 RAM 问题
- 创建一个简单的计算器,添加时遇到问题
- 问题创建和返回锯齿状阵列(错误std :: bad_array_new_length)
- 问题创建一个将一些文本放入qtextedit中的问题
- 问题:创建QStackedLayout
- C++问题创建类对象和循环包含
- c++作用域问题:创建一个矩阵类而不浪费空间