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

1 次查看(过去 30 天)
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!

采纳的回答

dpb
dpb 2014-11-1
编辑:dpb 2014-11-2
...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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Labels and Annotations 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by