how to save values to text file in specific format using matlab

≡放荡痞女 提交于 2019-12-11 22:17:18

问题


I have a matrix of values like [150 255 25;400 80 10;240 68 190]. I want to store these values to text file in hexadecimal format such that each value in matrix is represented by 3digit hexa value (12bit). i.e

Decimal Hexa notation 150 255 25 096 0FF 019 400 80 10 -> 190 050 00A 240 68 190 0F0 044 0BE

I am using like this

`fp=fopen('represen.dat','wb');
for i=1:1:x
   for j=1:1:y
       fprintf(fp,"%3x\t",A(i,j));
   end
   fprintf(fp,"\n");
end`

It is giving result as Decimal Hexa notation 150 255 25 96 FF 19 400 80 10 -> 190 50 0A 240 68 190 F0 44 BE

help me in this regard..


回答1:


To insert leading zeros your fprint command should look like this:

fprintf(fp,"%03x\t",A(i,j));


来源:https://stackoverflow.com/questions/18397552/how-to-save-values-to-text-file-in-specific-format-using-matlab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!