2×0 empty double matrix
44 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
sxh
el 4 de Sept. de 2024 a las 18:04
Comentada: Voss
el 5 de Sept. de 2024 a las 17:06
trying to calculate a function with matrix arguments and matrix output: Question 1: is the following code the right way to do it? Question 2: why is SAB21 returning " 2×0 empty double matrix"?
A = magic(4)
S = anti_eye(4)
S = star (S, A) %should return A
function SAB = star(SA,SB)
% Redheffer Star Product
SAB11 = SA (1:2,1:2,:) + SA (1:2,3:4,:) *((eye(2) - SB (1:2,1:2,:)* SA (3:4,3:4,:))^(-1)) *SB (1:2,1:2,:) *SA (3:4,1:2,:)
SAB12 = SA (1:2,3:4,:) *((eye(2) - SB (1:2,1:2,:) *SA (3:4,3:4,:))^(-1)) *SB(1:2,3:4,:)
SAB21 = SB (3:4,1:2,:) *((eye(2) - SA (3:4,3:4,:) *SB (1:2,1:2,:))^(-1)) *SA(3:4,2:1,:)
SAB22 = SB (3:4,3:4,:) + SB (3:4,1:2,:) *((eye(2) - SA (3:4,3:4,:) *SB (1:2,1:2,:))^(-1)) *SA (3:4,3:4,:) *SB (1:2,3:4,:)
SAB (1:2, 1:2 ,:) = SAB11;
SAB (1:2, 3:4 ,:) = SAB12;
SAB (3:4, 2:1, :) = SAB21;
SAB (3:4, 3:4, :) = SAB22;
end
function ans = anti_eye(n)
% anti Identity matrix
flipud(eye(n));
end
0 comentarios
Respuesta aceptada
Voss
el 4 de Sept. de 2024 a las 18:17
Editada: Voss
el 4 de Sept. de 2024 a las 18:26
"why is SAB21 returning " 2×0 empty double matrix"?"
Because the expression 2:1 evaluates to an empty vector.
SAB21 = SB (3:4,1:2,:) *((eye(2) - SA (3:4,3:4,:) *SB (1:2,1:2,:))^(-1)) *SA(3:4,2:1,:)
% ^^^
2:1
I guess you meant 2:-1:1, or simpler, [2 1]:
2:-1:1
[2 1]
Example:
M = magic(4)
M(3:4,2:1,:)
M(3:4,[2 1],:)
And by the way, the colon indexing in the third dimension, e.g.:
SA(3:4,[2 1],:)
% ^^
is not necessary anywhere in the code because all the arrays are two-dimensional (i.e., matrices). That is, you can just write
SA(3:4,[2 1])
etc.
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Colormaps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!