如何使用matlab以特定的格式将值保存到文本文件 [英] how to save values to text file in specific format using matlab
问题描述
十进制十六进制符号
150 255 25 096 0FF 019
400 80 10 - > 190 050 00A
240 68 190 0F0 044 0BE
我使用的是这样的
`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,\\\
);
end`
结果为
十进制十六进制
150 255 25 96 FF 19
400 80 10 - > 190 50 0 A
240 68 190 F0 44 BE
在这方面帮助我。 。
要插入前导零,您的 fprint
命令应该看起来像这样:
fprintf(fp,%03x\t,A(i,j));
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..
To insert leading zeros your fprint
command should look like this:
fprintf(fp,"%03x\t",A(i,j));
这篇关于如何使用matlab以特定的格式将值保存到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!