File Output format not in Hex in Designer, but is in .m file output

2 次查看(过去 30 天)
I am using Matlab 2019a Designer to dump some values to a text file. If I run the .m file on the command line (like a normal Matlab function), it outputs the data in hex format, as expected.
If I use the designer app and dump the data, it saves the data in decimal format. How can I get the output of my data to be in hex format like the .m file? Thanks!
Here is my code snippet:
% Format the coefficients in .mem format
Nd = Nf/Nl; % Word depth of memory for each vector
fd = fopen(fn, 'w');
fprintf(fd, '// SHAPE vector ROM for %s, contains %d vectors, each %d samples\n', band, K, Nf);
for k = 1 : K
for n = 0 : Nd-1
fprintf(fd, '@%04x ', Nd*(k-1)+n);
for m = Nl-1 : -2 : 1
data = xq(Nl*n+m+1,k)*pow2(3*Qc) + xi(Nl*n+m+1,k)*pow2(2*Qc) + xq(Nl*n+m,k)*pow2(Qc) + xi(Nl*n+m,k);
fprintf(fd, '%09x', data);
end
fprintf(fd, '\n');
end
end
fclose(fd);
  4 个评论
Scotty Mac
Scotty Mac 2023-9-14
编辑:Scotty Mac 2023-9-14
That almost fixed my issue. It is now outputting hex values, but the line lengths vary incorrectly....
In the original .m command line output, each line should be 288 bits, but now they are vary in lengths.
Here is a sample of the original output:
Now, an example of the same inputs, but an output of the Designer processed file (using same code as above):
After the rounding experiment above, the output looks like (closer to being correct, but not a match):

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2023-9-14
编辑:Walter Roberson 2023-9-14
reading off of your tooltip and converting:
format long g
g = hex2num('422ffbed66dbfd86')
g =
68685312877.9952
Not an integer.
The problem is not with output facilities: the problem is that somehow you are calculating differently.
  3 个评论
Scotty Mac
Scotty Mac 2023-9-14
编辑:Scotty Mac 2023-9-14
@Walter Roberson Thanks for the direction. I think it might have to do with how my inputs are ingested into the code. My inputs into the .m file are an array in the form of:
[5700e6, 4750e6, 4950e6]
For the GUI, my inputs are via an entry field and then multipled like:
x1 = str2double(app.EditField_Freq1.Value);
x1 = x1 * 10e5;
-- Then combine all x1,x2,x3 into an array.
array_x = [x1, x2, x3];
Should I be using str2num instead to more closly match the 5000e6 notation?
Scotty Mac
Scotty Mac 2023-9-14
编辑:Scotty Mac 2023-9-14
I will start a new question, since my output question has been answered and my problem is different issue.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by