problem in plotting data

조회 수: 1 (최근 30일)
Daniele Sonaglioni
Daniele Sonaglioni 2021년 11월 12일
댓글: Daniele Sonaglioni 2021년 11월 12일
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);
Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 902.572770
r=r(:)
r = 5×1
3.5956 2.7170 -0.0000 1.1588 -2.0959
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!

채택된 답변

Cris LaPierre
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.
  댓글 수: 1
Daniele Sonaglioni
Daniele Sonaglioni 2021년 11월 12일
Thank you @Cris LaPierre but I was experiencing a problem with Matlab and the plots were not visible. Anyway, I have subsequently improved the code with GlobalSearch.
Referring to the question above, the code was right, the only problem was with Matlab but now I have solved everything. If you can, I wuold ask if can delete the question because it is not useful for other users at all.
Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by