- -1/.5 == 2
- kron(eye(32), [-2, 0; 1, 0]) .* ones(64, 1) == kron(eye(32), [-2, 0; 1, 0])
- kron(ones(32), 1) == ones(32)
Error: Matrix dimensions must agree
1 view (last 30 days)
Show older comments
I am trying to execute this piece of code but cannot figure out why I am getting this error, any help is much appriciated.
yp=kron(eye(32),[-1/.5 0;1 0]).*ones(2*32,1)+80*pi.*kron(ones(32),1);[1/.5;0]+2.*90.*diag(ones(2*32-1,1),1).*(kron(ones(32,1),[;1/.5])).*cos(zeros(2*32-1,1)).*(sin(8.*((1/64):(1/64):10)-ones(2*32,1)))./.5
0 Comments
Accepted Answer
Jan
on 20 Apr 2021
Edited: Jan
on 20 Apr 2021
Seriously? Your code contains some jokes:
So a simplified version of the first line is:
yp = kron(eye(32), [-2, 0; 1, 0]) + 80 * pi * ones(32);
% [64 x 64] + [32 x 32]
This cannot work. If you really want to add this, omit the expanding of the 2nd term to a matrix:
yp = kron(eye(32), [-2, 0; 1, 0]) + 80 * pi;
The 2nd part ise useless at all, even if it would work, because the result is not assigned to a variable. So the best solution is simply to delete the 2nd line. By the way, this line contains invalid Matlab syntax:
[1/.5 ; 0] + 2 .* 90 .* diag(ones(63, 1), 1) .* ...
(kron(ones(32, 1), [;1/.5])) .* ...
... % ^ what should this be?!?
cos(zeros(63, 1)) .* sin(8 .* ((1/64):(1/64):10) - ones(64, 1)) ./ .5
% [63 x 1] .* [64 x 640] : cannot match
Expressions like cos(zeros(2*32-1,1)) are a waste of time, because cos(0)==1, so this replace this by ones(63,1).
But as said already: because this part of the code does not perform anything useless, it is easier to delete it than to fix it.
I cannot image a serious task, in which such code could appear.
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!