admin 管理员组

文章数量: 887021


2024年1月6日发(作者:kafka配置文件详解)

MATLAB下输出一个二维数组(以C语言格式)

clc;clear all;close all;

%%

%%计算DCT系数

P = 24; P2 = P/2;

for k=1:P2;

n = 0:P-1;

dctcoef(k,:) = cos((2*n+1)*k*pi/(2*P));

end

dctcoef = int16(dctcoef*2^15);

%%

%%特定格式输出到文件

fid = fopen('C:','wt'); %写入文件路径

matrix = dctcoef;

[m n] = size(matrix);

fprintf(fid,'const signed short int DCTCOEF[%d][%d]={n',m,n);

for i=1:m

fprintf(fid,'{');

for j=1:n-1

fprintf(fid,'%d,',matrix(i,j));

end

fprintf(fid,'%d},n',matrix(i,n));

end

fprintf(fid,'};');

fclose(fid);

文件夹下数据的格式如下:

const signed short int DCTCOEF[12][24]={

{32698,32138,31029,29389,27246,24636,21605,18205,14493,10533,6393,2143,-2143,-6393,-10533,-14493,-18205,-21605,-24636,-27246,-29389,-31029,-32138,-32698},

{32488,30274,25997,19948,12540,4277,-4277,-12540,-19948,-25997,-30274,-32488,-32488,-30274,-25997,-19948,-12540,-4277,4277,12540,19948,25997,30274,32488},

{32138,27246,18205,6393,-6393,-18205,-27246,-32138,-32138,-27246,-18205,-6393,6393,18205,27246,32138,32138,27246,18205,6393,-6393,-18205,-27246,-32138},

{31651,23170,8481,-8481,-23170,-31651,-31651,-23170,-8481,8481,23170,31651,31651,23170,8481,-8481,-23170,-31651,-31651,-23170,-8481,8481,23170,31651},

{31029,18205,-2143,-21605,-32138,-29389,-14493,6393,24636,32698,27246,10533,-10533,-27246,-32698,-24636,-6393,14493,29389,32138,21605,2143,-18205,-31029},

{30274,12540,-12540,-30274,-30274,-12540,12540,30274,30274,12540,-12540,-30274,-30274,-1254

0,12540,30274,30274,12540,-12540,-30274,-30274,-12540,12540,30274},

{29389,6393,-21605,-32698,-18205,10533,31029,27246,2143,-24636,-32138,-14493,14493,32138,24636,-2143,-27246,-31029,-10533,18205,32698,21605,-6393,-29389},

{28378,0,-28378,-28378,0,28378,28378,0,-28378,-28378,0,28378,28378,0,-28378,-28378,0,28378,28378,0,-28378,-28378,0,28378},

{27246,-6393,-32138,-18205,18205,32138,6393,-27246,-27246,6393,32138,18205,-18205,-32138,-6393,27246,27246,-6393,-32138,-18205,18205,32138,6393,-27246},

{25997,-12540,-32488,-4277,30274,19948,-19948,-30274,4277,32488,12540,-25997,-25997,12540,32488,4277,-30274,-19948,19948,30274,-4277,-32488,-12540,25997},

{24636,-18205,-29389,10533,32138,-2143,-32698,-6393,31029,14493,-27246,-21605,21605,27246,-14493,-31029,6393,32698,2143,-32138,-10533,29389,18205,-24636},

{23170,-23170,-23170,23170,23170,-23170,-23170,23170,23170,-23170,-23170,23170,23170,-23170,-23170,23170,23170,-23170,-23170,23170,23170,-23170,-23170,23170},

};


本文标签: 格式 文件 数组 配置文件