Dividing a matrix by a different size vector
Mostra commenti meno recenti
Hi,
I am trying to divide a "733x2 double" matrix by a "237x1 double" vector for a regression analysis.
The following is my code and data attached:
filename3 = 'TV_NYMA_Final';
[num,string,vt] = xlsread(filename3, 'NOx>25');
Year_N = num(:,1); County_N = string(:,2);
VOC_N = num(:,3); NOx_N = num(:,4);
standard_NOx_N = normalize(NOx_N); standard_VOC_N = normalize(VOC_N);
%
[num,string,vt] = xlsread(filename3, 'VOC>25');
Year_V = num(:,1); County_V = string(:,2);
VOC_V = num(:,3); NOx_V = num(:,4);
standard_NOx_V = normalize(NOx_V); standard_VOC_V = normalize(VOC_V);
%
X_N = [ones(length(standard_NOx_N),1) standard_NOx_N];
b = X_N\standard_VOC_V
regression_line_NV = [ones(size(standard_NOx_N,1),1) standard_NOx_N]*b
figure
scatter(standard_NOx_N, standard_VOC_V)
hold on
plot(standard_NOx_N, regression_line_NV)
The error occurs in the line "b = X_N\standard_VOC_V".
Error using \
Matrix dimensions must agree.
Is there a way to circumvent this error such as manipulating the data or reshaping the matrix to make the dimensions agree and how would I go about doing so?
Thanks.
4 Commenti
Rik
il 24 Mag 2021
How do you propose to divide a 733x2 matrix by a 237x1 vector?
John Ziggs
il 24 Mag 2021
Rik
il 24 Mag 2021
I don't understand what you mean mathematically, so I can't help you implement it in Matlab.
Stephen23
il 25 Mag 2021
"I thought of removing a row of data to make it into a 732x2 then reshaping and adding a few null datasets to make it into a 244x1 vector. "
How do you propose to "reshape" 732*2 (=1464) elements into fewer than 244 elements?
How to you propose to divide a 244 element vector by a 237 element vector?
Risposte (1)
Jan
il 24 Mag 2021
0 voti
The division of a [733x2] matrix by a [237x1] vector is not defined mathematically. Therefore it is impossible to apply any tricks to perform it in Matlab.
If you invent such a procedure, you have to explain, how it is applied. What is the expected output?
1 Commento
Or a simpler question: If you were to divide the following matrix by the vector in the same way you want to operate on your larger data, what should the result be and why?
A = reshape(1:12, 6, 2)
B = (13:17).'
Categorie
Scopri di più su Descriptive Statistics and Insights in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!