Help generating .coe file
16 views (last 30 days)
Show older comments
i have written a matlab code to generate .coe file. unfortunately .coe file is generated containing nothing. below is my code:
clear all;
N = 255;
B = 2;
div = (N-1)/(N+1);
c = atanh(div);
filename = 'catan.coe';
fid = fopen(filename,'wt');
fprintf(fid,'memory_initialization_radix=2;\n');
fprintf(fid,'memory_initialization_vector=\n');
for i=0:N-1
fprintf(fid,'%d,\n', c(i));
end
fprintf(fid,'%d;\n', c(N));
fclose(fid);
Please help me by rectifying the code to generate valid .coe file
0 Comments
Answers (1)
Walter Roberson
on 31 Oct 2011
In your loop, you have
for i=0:N-1
fprintf(fid,'%d,\n', c(i));
end
Notice that this will start by attempting to access c(0) . Indexing at location 0 is not permitted in MATLAB, so your code would crash.
Your earlier line included
div = (N-1)/(N+1);
with N being a scalar value. div will then be a scalar value, so when you calculate c = atanh(div), c is going to be a scalar value. But then the loop I pointed out above is going to try to access N different locations in that scalar value c.
Your code is ill beyond the point we can reasonably guess what you want to do.
2 Comments
Walter Roberson
on 31 Oct 2011
Perhaps you want
div = ((1:N)-1) ./ ((1:N)+1);
c = arctanh(div);
I do not know anything about .coe files, but there was a reference in another question, http://www.mathworks.com/matlabcentral/answers/1482-coe-file-in-matlab
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!