Dividing a matrix by a different size vector

9 次查看(过去 30 天)
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 个评论
Rik
Rik 2021-5-24
I don't understand what you mean mathematically, so I can't help you implement it in Matlab.
Stephen23
Stephen23 2021-5-25
"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?

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2021-5-24
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 个评论
Steven Lord
Steven Lord 2021-5-24
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)
A = 6×2
1 7 2 8 3 9 4 10 5 11 6 12
B = (13:17).'
B = 5×1
13 14 15 16 17

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by