Linear regression on a semi-log scale

조회 수: 28 (최근 30일)
James Mathew
James Mathew 2013년 6월 11일
Hi,
I'm trying to plot a linear regression line on a semi-log scale.
Y-axis Linear Received power in dB
X-axis Log distance in m
The program and data I'm using as as follows:
Inc=1;
D=10; %Max meaurement distance
d1=(1:Inc:D); %1m to max measurment distance (D) in Increments (Inc)
RXPdata1=[-45.0983; -53.3746; -54.4132; -56.8286; -59.2905; -60.2743; -60.6919; -59.4938; -64.0525; -62.6163]; %Measured data in dB
semilogx(d1,(RXPdata1(:,1)),'-or') %Plot measured data
hold on
%Graph Set up
title ('Plot showing measured data')
xlabel('Distance (m) [Log scale]')
ylabel('Recieved Power (dB)')
legend ('Measured Data','Location','EastOutside')
axis([0 10 -70 -35]);
hold on
grid on
Can anyone help?
James

채택된 답변

Miroslav Balda
Miroslav Balda 2013년 6월 11일
The following code solves your problem:
% James.m
% JAMES Linear regression on a semilog scale
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2013-06-11
%
% Miroslav Balda
% miroslav AT balda DOT cz
%
Inc=1;
D=10; % Max meaurement distance
%
d1=(1:Inc:D); % 1m to max measurment distance (D) in Increments (Inc)
RXPdata1=[-45.0983; -53.3746; -54.4132; -56.8286; -59.2905; -60.2743;...
-60.6919; -59.4938; -64.0525; -62.6163]; % Measured data in dB
%
semilogx(d1,(RXPdata1(:,1)),'-or') % Plot measured data
hold on
%
% % Graph Set up
%
title ('Plot showing measured data','FontSize',14, 'FontWeight','bold')
xlabel('Distance (m) [Log scale]','FontSize',10, 'FontWeight','bold')
ylabel('Recieved Power (dB)','FontSize',10, 'FontWeight','bold')
%
axis([0 10 -70 -35]);
hold on
grid on
%
% Regression
%
logd1 = log10(d1');
A = [ones(size(RXPdata1)),logd1];
c = A\RXPdata1
y = A*c;
plot(d1,y,'o-', d1,y,'*-')
%
legend ('Measured Data','Lin. Regression','Location','EastOutside')
It is all. Good luck!
Mira
  댓글 수: 2
James Mathew
James Mathew 2013년 6월 11일
Mira,
Many many thanks, this has saved me hours of work!!!
James
James Mathew
James Mathew 2013년 6월 18일
Mira,
Me again, any chance you could help me out again. If trying to find the following variables for the line:
- where the line intersects 0 (or it is 1?) - the gradient - the regression coefficient
Thanks in advance.
James

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by