이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
how can curve fitting
조회 수: 1 (최근 30일)
이전 댓글 표시
hi...i have some scatter points in x-y coordinate.how can curve fitting without using of cftool?i want do it by gussian fitt but in gussian code there are x and y.i domt know how obtain them!
% f = fit(x,y,'gauss8'); % plot(f,x,y); % coeff=fit(x,y,ft);
G is sample matrix with 106*47 in size and meanValue is mean of columns in matrix.result matrix is 1*47 that it is scatter points.
meanValue = mean(G)
thank you
댓글 수: 1
Image Analyst
2014년 5월 17일
A screenshot of your data, or attaching your data file, would help us envision what you're talking about.
채택된 답변
Star Strider
2014년 5월 17일
Here’s my version of Gauss1 using fminsearch:
% % Single Gaussian Regression
% % Generate x- and y- data:
% x = linspace(0,10); % Generate x-data
% Normal distribution — b(1) = mean, b(2) = std
N = @(b,x) exp(-((x-b(1)).^2)./(2*b(2)^2)) ./ (b(2)*sqrt(2*pi));
% b = [5; 1];
% d1 = N(b,x); % Generate smooth y-data
% d2 = d1 + 0.05*(rand(size(d1))-.5); % Add noise
% % ————— Assign your variables to x and y here —————
x = your independent variable
y = your dependent variable
% % Use ‘fminsearch’ to do regression:
y = d2;
OLS = @(b) sum((N(b,x) - y).^2); % Ordinary Least Squares cost function
opts4 = optimset('MaxFunEvals',50000, 'MaxIter',10000);
B = fminsearch(OLS, rand(2,1))
Nfit = N(B,x); % Calculate estimated fit
The variables you need to have in your workspace are x and y (or assign them to x and y) to use this without modifying the code. The single ‘%’ commented lines are there for illustration. (Uncomment them if you want to see how it works. Remove them if you don’t need them.)
댓글 수: 27
Star Strider
2014년 5월 17일
I downloaded and fit the data in ‘meanValue.fig’. I changed my code to a 2-Gaussian model, and got what I consider a decent fit.
You will have to assign your x and y variables to the ones I call x and y in my code, just after my comment:
% % ————— Assign your variables to x and y here —————
after that, it should run without problems.
Initial choice of parameters, especially b(2) and b(5) in N2, is important in situations like these, since it’s possible for both Gaussian functions to fit to same peak, ignoring the other one.
I got for the fitted parameter set:
B =
584.9265
28.8754
4.3951
312.9486
38.4016
2.6977
fitting to your data with this code:
% % Double Gaussian Regression
N = @(b,x) b(1).*exp(-((x-b(2)).^2)./(2*b(3)^2)) ./ (b(3)*sqrt(2*pi));
N2 = @(b,x) b(1).*exp(-((x-b(2)).^2)./(2*b(3)^2)) ./ (b(3)*sqrt(2*pi)) + b(4).*exp(-((x-b(5)).^2)./(2*b(6)^2)) ./ (b(6)*sqrt(2*pi));
% % ————— Assign your variables to x and y here —————
x = ...;
y = ...;
% % Use ‘fminsearch’ to do regression:
OLS = @(b) sum((N2(b,x) - y).^2); % Ordinary Least Squares cost function
opts4 = optimset('MaxFunEvals',50000, 'MaxIter',10000);
B = fminsearch(OLS, [50 25 5 50 40 5]')
N2fit = N2(B,x); % Calculate estimated fit
Nfit(1,:) = N(B(1:3),x);
Nfit(2,:) = N(B(4:6),x);
figure(1)
plot(x, y, '+b')
hold on
plot(x, N2fit, '-r', 'LineWidth',1.5)
plot(x, Nfit(1,:), '-g')
plot(x, Nfit(2,:), '-g')
hold off
grid
text(5, 55, sprintf('Centre #1 = %.2f, \\sigma #1 = %.2f\nCentre #2 = %.2f, \\sigma #2 = %.2f', B(2:3), B(5:6)), 'FontName','Consolas', 'FontSize',7)
producing this plot:
fereshte
2014년 5월 18일
편집: fereshte
2014년 5월 18일
dear Star Strider thanks a lot....great.very good.but i dont run it.error:
??? Error: File: Untitle.m Line: 6 Column: 3 The expression to the left of the equals sign is not a valid target for an assignment.
some Question?
1.Which line in this code read the my input image?
2.Is this code for any other data?
3.b Parameter must be calculated for each image?
4.how obtain coefficients by this code?they are important for my work.
Star Strider
2014년 5월 18일
I omitted the lines that read your image because I thought you had access to those data without them. If you want to use that and other images (nothing wrong with that), insert these lines before the comment line:
ssf = openfig('meanValue.fig')
hf2 = get(gca, 'Children');
hf3xc = get(hf2, 'XData');
hf3yc = get(hf2, 'YData');
% % Double Gaussian Regression
then:
% % ————— Assign your variables to x and y here —————
x = hf3xc;
y = hf3yc;
If you want to use other figures as sources of data, simply insert their names in the openfig line. It should run without problems, although you might need to change the values for b(2) and b(5) as I mentioned previously, to initially approximate the centres of the peaks of your data.
I’ll re-post the entirety of my code if necessary, but these are the only changes you need to make it work. The code should work for all sets of x and y data that you want to give it. Unless you use your ‘.fig’ files as input (in which situation you only need to change their names in the openfig statement), you simply have to use the code in my previous comment, plug in the names of your variables in place of hf3xc and hf3yc in my code, and adjust two of the initial parameter estimates. The program should then successfully estimate all the parameters.
fereshte
2014년 5월 18일
The program successfully run. dear friend, thank you so much for your help.youre very clever.Good luck in your life. only if it is possible help me to get code that calculate b(2) and b(5) for other images.
Star Strider
2014년 5월 18일
My pleasure!
The sincerest and most valuable expression of thanks in MATLAB Answers is to Accept the Answer that is closest to answering your Question and solving your problem.
This code will calculate b(2), b(5) for all images of this type. You will have to give initial estimates for b(2), b(5) unless they are in approximately the same locations as they were in the figure you posted. In this situation, it is possible to create a function file out of my code, but I need to know more about the other images you want to analyse with it, and if you only want to analyse your images with it.
fereshte
2014년 5월 18일
my database are footprint images of different people.I will run examples of them and compare with meanValue curve if they arent in the same locations,will post here.I've no word to express my seep gratitude.thank you for your time
Star Strider
2014년 5월 18일
I asked because it has a findpeaks function that would help locate the peaks for you to estimate subsequently. You can use the max function to find the highest peak and its index (to define the x-coordinate of the peak).
If the first peak is always the highest, set that initial estimate as b(2), and define b(5)=b(2)+10 for its initial estimate.
Simply an idea to make your analysis easier!
fereshte
2014년 5월 19일
in cftool, gauss 8 give me best fit of curve. this program generate a code for gauss 8 but i dont run it.i need to code to run for every image of right and left footprint.i dont write in command window cftool for every image and run it.its Boring.
Star Strider
2014년 5월 19일
I don’t have the curve fitting toolbox (I don’t need it with the Statistics and Optimization Toolboxes) so I can’t help you with it.
Did setting the initial values to b(2)=20, b(5)=40 work?
Star Strider
2014년 5월 19일
If I have time today, I’ll expand the two-peak plot to four and let you experiment with it.
fereshte
2014년 5월 19일
can i find x-coordinate of peaks by this code?
[~,locs_Rwave] = findpeaks(meanValue);
fereshte
2014년 5월 22일
편집: fereshte
2014년 5월 22일
Sorry. by this code,i get the peak values, but sometimes I obtain 3 or 4 values for peak 1- Which values of these important(max of them)?
2-Is there the code to replace these values in the formula and I do not need to enter them manually for each of the image?
fereshte
2014년 6월 4일
Star Strider
how obtain b(1),...b(5) for any image? i only get b(2) and b(5) by [~,locs_Rwave] = findpeaks(meanValue);
Star Strider
2014년 6월 4일
I suggest you fit them as I did in my code. Use estimates for b(2) and b(5) from findpeaks as your initial parameter estimates for those elements in the call to fminsearch.
Image Analyst
2014년 6월 29일
Please put that "Answer" right here. No need to put a comment here and then say that Star has to look somewhere else down the page for it, especially since it's not really an "Answer" to your original post but a comment to Star.
fereshte
2014년 6월 29일
편집: fereshte
2014년 6월 29일
dear Star Strider
i use youre code for my dataset. but it dont work for all images. i change B line in this code respect to locs_Rwave for some images that dont get me true response.but its very difficult.can you help me to get the code that run perfectlly for all images with out any change in B line?
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Descriptive Statistics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)