write equation automatically and create a file which save the constant term of the equation

1 view (last 30 days)
Hi all! I have a script for plot data. My script is:
for k=159:100:2048
ix=isfinite(LOGIR(:,k));
x=XMEAN(ix);
y=LOGIR(ix,k);
idx=[1:14]
p=polyfit(x(idx),y(idx),1);
yfit=polyval(p,x);
figure(k);
plot(x(idx),y(idx),'.',x,yfit,'r')
gtext(['y=',num2str(p(1)),'x+',num2str(p(2))])
xlabel('airmass')
ylabel('logirradiance')
print(sprintf('Figure(%d).bmp',k), '-dbmp')
end
I want the equation to appear automatically on the graph and not I place each one. Also, I want to create a file which will save the constant term of each equation. How can I do this?
Thank you!

Accepted Answer

dpb
dpb on 1 Nov 2014
Edited: dpb on 2 Nov 2014
...I want the equation to appear automatically on the graph and not I place each one.
Use text instead of gtext You'll have to use some pre-knowledge of what your curves look like to put it near the line where it doesn't interfere or pick a position known to be out of the way (like upper left or lower right).
xlab=some_x_position_in axes coordinates;
ylab=same_for_y;
text(x,y,num2str('y=%0.3f*x+%0.3f',p)
_ ...create a file which will save the constant term of each equation..._
Open the file before starting the loop and write each p(2) when it's been calculated.
fid=fopen('Yourdesiredfilename','wt');
for ...
...
fprintf(fid,'%f\n',p(2));
end
fid=fclose(fid);

More Answers (0)

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!