Borrar filtros
Borrar filtros

BSXFUN Non-singleton dimensions of the two input arrays must match each other

2 visualizaciones (últimos 30 días)
SV= 5x3 double
-942906.419536844 313828.010191792 -97267.0565510760
-3230319.32628628 274998.490952776 -360706.320861567
-3654652.46885917 188670.898935597 -360709.467463522
-3154108.93174870 356508.559368121 -274070.151413514
-518048.989052842 163395.251935092 -97278.8122561220
NED= 15x3 double
0.171851776223634 0.562101832252225 0.809016994374948
-0.0984473987127902 0.621572412738697 0.777145961456971
-0.152246381942301 0.610626885893996 0.777145961456971
-0.0856835166627207 0.609669900169326 0.788010753606722
0.220188231021396 0.544984995878047 0.809016994374948
0.956304755963035 -0.292371704722737 0
0.987688340595138 0.156434465040231 0
0.970295726275997 0.241921895599668 0
0.990268068741570 0.139173100960065 0
0.927183854566787 -0.374606593415912 0
0.236533677795068 0.773666799375683 -0.587785252292473
-0.121572412738697 0.767578005071649 -0.629320391049837
-0.188008624153297 0.754061405094349 -0.629320391049837
-0.109669900169326 0.780341887121718 -0.615661475325658
0.303063100278379 0.750107495254601 -0.587785252292473
M=bsxfun(@times,NED,SV);
Error using bsxfun
Non-singleton dimensions of the two input arrays must match each other.
I am just trying to multiply these two matricies (I believe element by element), I don't understand why the zeros must match each other (my interpretation of the error)
  5 comentarios
olivia
olivia el 12 de Sept. de 2023
That should be multiplied by the first row of SV:
-942906.419536844 313828.010191792 -97267.0565510760
Dyuman Joshi
Dyuman Joshi el 12 de Sept. de 2023
Editada: Dyuman Joshi el 12 de Sept. de 2023
3x3 and 3x1 are compatible for element wise multiplication.
15x3 and 5x3 are not compatible for element wise multiplication. (They are also not comptaible for matrix multiplication)
Please go through this documentation page to learn more about compatible sizes for various operations - https://in.mathworks.com/help/matlab/matlab_prog/compatible-array-sizes-for-basic-operations.html
Edit - "That should be multiplied by the first row of SV:"
Do you want to multiply each row of NED with each row of SV?

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 12 de Sept. de 2023
Editada: Stephen23 el 12 de Sept. de 2023
"That should be multiplied by the first row of SV:"
I am guessing that you want to repeat SV so that it has as many rows as NED, and then multiply them together element-wise (a more accurate description would avoid the need to guess). Perhaps like this:
SV = [-942906.419536844,313828.010191792,-97267.0565510760; -3230319.32628628,274998.490952776,-360706.320861567; -3654652.46885917,188670.898935597,-360709.467463522; -3154108.93174870,356508.559368121,-274070.151413514; -518048.989052842,163395.251935092,-97278.8122561220]
SV = 5×3
1.0e+06 * -0.9429 0.3138 -0.0973 -3.2303 0.2750 -0.3607 -3.6547 0.1887 -0.3607 -3.1541 0.3565 -0.2741 -0.5180 0.1634 -0.0973
NED = [0.171851776223634,0.562101832252225,0.809016994374948; -0.0984473987127902,0.621572412738697,0.777145961456971; -0.152246381942301,0.610626885893996,0.777145961456971; -0.0856835166627207,0.609669900169326,0.788010753606722; 0.220188231021396,0.544984995878047,0.809016994374948; 0.956304755963035,-0.292371704722737,0; 0.987688340595138,0.156434465040231,0; 0.970295726275997,0.241921895599668,0; 0.990268068741570,0.139173100960065,0; 0.927183854566787,-0.374606593415912,0; 0.236533677795068,0.773666799375683,-0.587785252292473; -0.121572412738697,0.767578005071649,-0.629320391049837; -0.188008624153297,0.754061405094349,-0.629320391049837; -0.109669900169326,0.780341887121718,-0.615661475325658; 0.303063100278379,0.750107495254601,-0.587785252292473]
NED = 15×3
0.1719 0.5621 0.8090 -0.0984 0.6216 0.7771 -0.1522 0.6106 0.7771 -0.0857 0.6097 0.7880 0.2202 0.5450 0.8090 0.9563 -0.2924 0 0.9877 0.1564 0 0.9703 0.2419 0 0.9903 0.1392 0 0.9272 -0.3746 0
R = size(NED,1)./size(SV,1); % -> 3
out1 = NED .* repmat(SV,R,1)
out1 = 15×3
1.0e+06 * -0.1620 0.1764 -0.0787 0.3180 0.1709 -0.2803 0.5564 0.1152 -0.2803 0.2703 0.2174 -0.2160 -0.1141 0.0890 -0.0787 -0.9017 -0.0918 0 -3.1905 0.0430 0 -3.5461 0.0456 0 -3.1234 0.0496 0 -0.4803 -0.0612 0
If you really want to use BSXFUN and get the same result:
S = size(SV);
out2 = reshape(bsxfun(@times,...
reshape(NED,S(1),R,S(2)),...
reshape( SV,S(1),1,S(2))),size(NED))
out2 = 15×3
1.0e+06 * -0.1620 0.1764 -0.0787 0.3180 0.1709 -0.2803 0.5564 0.1152 -0.2803 0.2703 0.2174 -0.2160 -0.1141 0.0890 -0.0787 -0.9017 -0.0918 0 -3.1905 0.0430 0 -3.5461 0.0456 0 -3.1234 0.0496 0 -0.4803 -0.0612 0
checking:
isequal(out1,out2)
ans = logical
1

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by