Help generating .coe file

16 views (last 30 days)
debalina ghosh
debalina ghosh on 31 Oct 2011
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

Answers (1)

Walter Roberson
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
debalina ghosh
debalina ghosh on 31 Oct 2011
thank you sir, but if i write
for i = 1 : N-1
.
.
.
will it generate the .coe file with vali coefficients?
i want to generate arctanh coefficients followig the formula atanh((a-1)/(a+1)),where a = natural number,
so here i teke a as N = 255. now sir plz help me.
Walter Roberson
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

Sign in to comment.

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!