Hi all. I'm trying to fit this two lines on matlab. I take the last 30 second of my experiment, the sampling is 2 data per second so i take the last 60 points. 40 before the peak and 20 after it.
I'd like to do a linear regression on the first 20 datas and then make a straight line. (Blue line) But using polyfit I've a curve on it. How can I make a straight line in a semilogy? I can't understand the equation to use in this case. I don't know where to put the 10 or the e. Also I'd like to consider the tangent from the peak to the second before. But if i'm able to do it for two point i can't elongate the red line to the blue line. Then i'd like to find the intercept of this two line. How can I do it mathematically? Anyone can help? this is the code i'm using
time=all_data(:,1);voltage=all_data(:,3);current=all_data(:,4);power=current.*voltage/(0.7*2*4);logpower=log(power);maxt=find(power==max(power));timebef=time(maxt-40:maxt+20);powerbef=power(maxt-40:maxt+20);close allfig=figure(j);set(fig,'units','normalized','outerposition',[0 0 1 1])semilogy(time,power,'LineWidth',2,'Color',[0 0 0]);xlim([min(timebef),max(timebef)]);xlabel('time (s)');ylabel('Log Power density mW/mm^3');set(gca,'FontSize',16);ylim([10,10000]);ylabel('Pow Den mW/mm^3');xlabel('time (s)');title(lista(j,:));hold onslope=polyfit(time((maxt-40):(maxt-20)),power((maxt-40):(maxt-20)),1);Y1=(slope(1).*time((maxt-40):(maxt+20)))+slope(2);semilogy(time((maxt-40):(maxt+20)),Y1,'LineWidth',2,'Color',[0 0 1])X2=[time(maxt-2) time(maxt)];Y2=[power(maxt-2) power(maxt)];semilogy(X2,Y2,'LineWidth',2,'Color',[1 0 0])
Best Answer