Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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!

Risposta accettata

dpb
dpb il 1 Nov 2014
Modificato: dpb il 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);

Più risposte (0)

Categorie

Scopri di più su Labels and Annotations in Help Center e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by