试图创建矩阵图,但出现了问题

Trying to create a matrix plot, but something is wrong

本文关键字:问题 创建      更新时间:2023-10-16

现在,该程序的主要目标是创建一个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];