BSXFUN Non-singleton dimensions of the two input arrays must match each other
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Dyuman Joshi
il 12 Set 2023
Modificato: Dyuman Joshi
il 12 Set 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?
Risposta accettata
Stephen23
il 12 Set 2023
Modificato: Stephen23
il 12 Set 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]
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]
R = size(NED,1)./size(SV,1); % -> 3
out1 = NED .* repmat(SV,R,1)
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))
checking:
isequal(out1,out2)
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrices and Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!