How to perform linear regression between respective columns of two matrix/table?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ranit
am 20 Jan. 2023
Kommentiert: Star Strider
am 23 Jan. 2023
I have two matix/ table. For example,
Table 1:

Table 2:

I want to fit linear regression between respective columns of the two tables. For example, column 1 in Table 1 are y values. Column 1 in Table 2 are x values. I want to get slope and intercept of linear regression between these two columns. Then the same for column 2, 3 and so on. At the end I should have n different slope and intercept pair (suppose each table has total n columns) collected in a matrix or table.
P.S.:
Edit: I would also really like to know any approach without using a for loop.
0 Kommentare
Akzeptierte Antwort
Star Strider
am 20 Jan. 2023
One approach —
A1 = randn(5,10) % Y-Values
A2 = randn(5,10) % X-Values
Rows = size(A1,1);
for k = 1:size(A1,2)
B(:,k) = [A2(:,k) ones(Rows,1)] \ A1(:,k);
end
Results = array2table(B.', 'VariableNames',{'Slope','Intercept'}, 'RowNames',compose('Col %4d',1:size(A1,2)))
.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Linear Regression finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!