I am asking a short question because I would like to have some opinions on the ideal dimensions that you require/use for a MATLAB figure in a publication.
I am using a direct built-in function of MATLAB in order to generate a figure with appropriate dimensions but I keep being unsatisfied about the result...
My LaTex text document is : width = 470 inches, height = 720 inches.
What do you think is more relevant ?
Thank you for your attention,
I would suggest to you save your figure using the function axis tight and define a function to export all your figures.
I've learned to avoid cropping the figure inside LaTeX to reduce compiling time, and I'm using the function below to export all my graphics. Complete Description. It exports figures like this one: Figure Example
function savefig_tight(h, outfilename)
set(h,'Units','Inches');
pos = get(h,'Position');
set(h,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)]);
print(outfilename ,'-dpdf','-fillpage');
end
Related
I was do curve fitting on a custom function in matlab (lsqcurvefit()) , I wanted to get some information in each iteration like estimated parameters (p1,p2,p3,p4) and errors to plot some informative graphs.
I used option('iter') input but it doesn't show them(actually i need their values to plot them) .
fun=#(p,t) p(1)*exp(-t./p(2)) + p(3)*t.*exp(-t/p(4));
options = optimoptions('lsqcurvefit','PlotFcn','optimplotresnorm' ,'Algorithm','levenberg-marquardt','Display','iter-detailed');
[p,resnorm,residual,~,~,lambda,jacobian] = lsqcurvefit(fun,[100,100,100,100],t,y,[],[],options);
it is my code. thank you for helping me.
I am very new to mat lab and I am trying to get to grips with integrating under a curve.
I wanted to see this difference between using the 'trapz(y)' and 'trapz(x,y)' to find the area under a curve of a Gaussian function what I can not seem to understand is why I am getting two different area values and I am trying to figure which one is more accurate.
dataset = xlsread('Lab 3 Results 11.10.18 (1).xlsx','Sheet3','C6:D515');
x=dataset(:,1);
a1=38.38;
b1=1179;
c1=36.85;
d1=6.3
y=a1*exp(-((x-b1)/c1).^2)-d1;
int1=trapz(x,y)
int2=trapz(y)
So when I run this code I get int1=1738.3 and int2=5.78.4 but when I integrated this function by hand using the trapezium rule my ans came out to be nearer int1 rather that int2 is there anyone that could shed some light on this if possible? I just cant imagen visulay how matlab is using the trapz rule two different ways,
Neither implementation is more accurate, but trapz(y) assumes unit spacing of each data point (e.g., spacing between data points is uniformly x = 1). See trapz documentation.
Since you know the x-coordinates, use trapz(x,y).
I've been trying to implement this equation into matlab:
http://www.mathworks.com/matlabcentral/answers/uploaded_files/46747/Capture.PNG
Omega is some known region of the image u1.
and p1,i is:
http://www.mathworks.com/matlabcentral/answers/uploaded_files/46748/Capture1.PNG
Pay attention: u1 is an image (column ordered), an p1,i is supposed to be calculated in each pixel of this image.
Now, I've calculated p1,i in this way:
[f1,xi1] = ksdensity(u1(:),1:255);
p1_u1 = reshape(f1(floor(u1(:))+1),M,N);
Now my problem is to calculate the former equation.
I've tried with for loop but its taking forever..
Any other suggestions? Maybe there's a way using ksdensity and change the value inside the integral?
Thanks!
I am trying to add Gaussian fit to the histogram in MATLAB, but I do not know how to apply the fit to one particular peak only.
http://postimg.org/image/phms61rdh/ first plot
http://postimg.org/image/sindrn8er/ second plot
I am also posting part of the code I have been using:
data_Rb = (importdata('path\name.txt'));
counts_Rb = data_Rb.data(:,3);
figure
hist(counts_Rb, nbins);
xlim([0 120]);
title('Rubidium');
histfit(counts_Rb,1000);
pd=fitdist(counts_Rb(:),'normal')
x=0:0.001:120;
PDF=pdf(pd,x); %PDF is a vector of y values: it's our fit
PDF=PDF/max(PDF); %nor
y=ylim;
PDF=PDF*y(2);
hold on
plot(x,PDF,'r-','LineWidth',2);
hold off
These two blocks give me two different Gaussians as shown in the first picture. I do not understand why they fit data so badly: is it because of the tail on the RHS?
In the second plot I need to apply Gaussian fit to the last peak only. How should I do it?
And finally, after applying the fit, fit results are outputed onto the screen. Is there a function to save them into an array or so for later use?
Thanks in advance!
Regarding your last question, see How can I access the fitted distribution parameters from the HISTFIT function in Statistiics Toolbox ?
There is a workaround for this isssue by making a copy of the HISTFIT
function and modifying the code to pass out the "pd" variable. One way
to do this is to change the "h" output on the first line of the code
to "varargout" and add the following to the end of the file:
h = [hh; hh1];
argout={h,pd};
if nargout > length(argout)
error('Too many output arguments.');
end
[varargout{1:nargout}]=argout{1:nargout};
Is there a way to display the curvefit equation on the graph produced without having to write it down myself manually every time? By GUI or command-line, anything is okay. Any hacks, some way to get around this?
Probably easiest to use the fit utility which is the non-graphical equivalent of using curvefit:
% sample data
x=[1:10]';
y = x+randn(10,1)*0.5;
plot(x,y,'o')
pars=fit(x,y,'poly1');
pars contains the result of the fit, which you can overlay on the plot above with
hold on
plot(pars)
If you want to see the values of individual parameters, you can type pars.p1 or pars.p2 (for this example, there may be other parameters "pn" for other models)
To display on the figure, you can do something simple like
xpos=3;
ypos=9;
text(xpos,ypos,{num2str([pars.p1;pars.p2])})
For more info look into the documentation for curvefit or try help curvefit or help fit.