problem in plotting data
조회 수: 1 (최근 30일)
이전 댓글 표시
Goodmorning,
I am doing a fit with a complex function: the code seems to work correctely but I cannot plot the data.
Do you have suggestion about what the problem is?
I attach the code I am working on and the data.
close all
clear
clc
load 'f_B100_PEGNA_t30_bisSC.txt'
f_B100_PEGNA_t30_bisSC;
f=f_B100_PEGNA_t30_bisSC(:,1);
yR=f_B100_PEGNA_t30_bisSC(:,6);
yI=f_B100_PEGNA_t30_bisSC(:,7);
Y=yR-1i*yI;
DER=yR.*0.01;
DEI=yI.*0.01;
DE_tot=DER+1i*DEI;
weightR=1./DER;
weightI=1./DEI;
weightT=1./DE_tot;
fit_fun=@(r,f) abs(r(1))+abs(r(2))./(1+(1i*f*2*pi*r(3)).^(abs(1-abs(r(4))))).^(r(5));
fit_funw=@(r) norm(weightR.*real(fit_fun(r,f)-Y)+1j*weightI.*imag(fit_fun(r,f)-Y));
r0=[1,1,1,1,1];
r=fminsearch(fit_funw,r0);
r=r(:)
figure(1)
loglog(f,yR,'o',f,real(fit_fun(r,f)))
figure(2)
loglog(f,yI,'o',f,-imag(fit_funw(r)))
Thank you all!
댓글 수: 0
채택된 답변
Cris LaPierre
2021년 11월 12일
I changed your post to executable code and ran in here. Two plots were created. Are those the figures you are trying to create? I suspect you expect to see a line in the second plot?
Upon inspection, the result of fit_funw(r) is a single number, 902.5728. It is not a complex number, so the result of imag is 0.
By default, the plot function does not include a markerstyle. It just plots using a solid line. When you data is a single point, you cannot see that line. This is because norm returns a single value for a vector input. Specify a marker style for the second plot.
If you expect fit_funw to return a vector, please check your approach.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!