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!