c - 在 C 中将这些数据表示为矩阵形式

标签 c matrix plot

我编写了如下代码:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  #define SIZE 1000

  FILE *fp = NULL;
  int i = 0;
  size_t  bytes = 0;

  if ((fp = fopen("raw_data.ht3", "rb")) == NULL) {
    printf ("could not open file\n");
    return 0;
  }
  fclose(fp);
  return 0;
}

这只是为每个读取的数据提供一个整数。我需要以矩阵形式呈现这些数据。矩阵的形式为 500 x 349。我如何呈现这样的数据?根据这些数据,我稍后将制作一个矩阵图。谢谢!我们将不胜感激您的帮助。

最佳答案

不要使用您当前拥有的 union ,而是执行以下操作:

typedef union
{
  uint8_t  u8 [2];
  uint16_t u16;
} meaningful_name_here;

那么你可以这样做

meaningful_name_here stuff [1000];

meaningful_name_here stuff [500][349];

另请记住,不应在堆栈上分配像这样的大型数组。将它们分配为静态或动态分配。

关于c - 在 C 中将这些数据表示为矩阵形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46832088/

相关文章:

algorithm - 计算二进制矩阵中的所有路径

arrays - Julia 中的循环创建矩阵

python - Python : Why do I get error message when I try to calculate the inverse of my 2x2-matrix (Hessian)?

linux - 通过对列进行分组,使用 gnuplot 绘制多个图

c - 在 while 循环中使用 scanf

c - semaphore.c 中的等待列表实现

c - 害怕 c 中的奇怪行为

c - c中的内存分配结构指针数组

d3.js - 使用 Vega 生成 3D 曲面图?

r - R中箱线图中的上下四分位数