matlab写coe文件

我在此举一个实例说明,我在此创建一个h矩阵,并将此矩阵写在rom1.coe文件中 。
[html] view plain copy
print ?
  1. h=randint(4,50);  
  2. fid1 = fopen('rom1.coe','w+');  
  3. fprintf(fid1,'memory_initialization_radix = 2;\n');  
  4. fprintf(fid1,'memory_initialization_vector =\n');  
  5. for i=1:4  
  6.     fprintf(fid1,'%x',h(i,:));  
  7.     fprintf(fid1,'\n');  
  8. end  
  9. fclose(fid1);  
h=randint(4,50);
fid1 = fopen('rom1.coe','w+');
fprintf(fid1,'memory_initialization_radix = 2;\n');
fprintf(fid1,'memory_initialization_vector =\n');
for i=1:4
    fprintf(fid1,'%x',h(i,:));
    fprintf(fid1,'\n');
end
fclose(fid1);
    结果如下
[html] view plain copy
print ?
  1. memory_initialization_radix = 2;  
  2. memory_initialization_vector =  
  3. 10110001111001011001110101011011011010011000000101  
  4. 10011000100000001011100100111000100101000001100100  
  5. 01101001100100100111011111011100000010100101000110  
  6. 00100110000000111010010010100101000111001101000011  

你可能感兴趣的:(matlab)