How can i code a Linreg for imported data (Elimination Capacity vs Loading Rate)

2 views (last 30 days)
Amil Ali on 2 May 2023
Edited: Vijeta on 15 May 2023
Hi guys - Im having some issue with perfoming via code on doing LinReg on the following imported data. I would like to calculate Linear regression on the variables named "Elimination Capacity" vs "Loading Rate". Can someone please give an coded solution - the goal is to plot in the code below. Please se code and its corresponding comments for guides.
%Defining and Importing data
filename = 'CATValuesoct22.xlsx';
% Assign the columns to variables
EliminationCapacity = data(:,1); % elimination capacity is in the first column
RemovalEfficiency = data(:,3); % removal efficiency is in the third column
EliminationCapacity_100 = data(:,2);
%HOW CAN I CODE IT and use it in the code for plot below
%plot for oct
% Create a figure
figure
% Set the first y-axis
yyaxis left
ylabel('Removal Efficiency [%]');
% Set the second y-axis
yyaxis right
ylabel('Elimination Capacity [g/(m^3*h)]');
hold on
% Set x-axis
title('October');
legend('Removal Efficiency', 'Elimination Capacity','100% Elimination Capacity');
Best Regards - Amil Ali

Vijeta on 15 May 2023
Edited: Vijeta on 15 May 2023
To calculate the linear regression between the variables "Elimination Capacity" and "Loading Rate" and plot the results, you can use the polyfit function in MATLAB. Here's how you can modify your code to include the linear regression calculation and the corresponding plot:
matlabCopy code :
% Defining and Importing data
filename = 'CATValuesoct22.xlsx';
% Assign the columns to variables
EliminationCapacity = data(:,1); % elimination capacity is in the first column
RemovalEfficiency = data(:,3); % removal efficiency is in the third column
EliminationCapacity_100 = data(:,2);
% Perform linear regression
% Plot for oct
% Create a figure
figure
% Set the first y-axis
yyaxis left
ylabel('Removal Efficiency [%]');
% Set the second y-axis
yyaxis right
hold on
% Set x-axis
title('October');
legend('Removal Efficiency', 'Elimination Capacity','100% Elimination Capacity', 'Linear Fit');
grid on;
In the above code, polyfit is used to calculate the coefficients of the linear regression line. The polyvalfunction is then used to evaluate the linear fit at each point along the LoadingRate values. Finally, the linear fit is plotted on the figure using plot along with the other data.
Make sure you have the appropriate data file ('CATValuesoct22.xlsx') in the current working directory or provide the correct path to the file.

Categories

Find more on Linear Predictive Coding in Help Center and File Exchange

R2020a

Community Treasure Hunt

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

Start Hunting!