Either I or matlab is going crazy with vertcat using brackets
Afficher commentaires plus anciens
Someone please point out what is going on with this piece of code. Matlab is running the first 3 concatenations fine, and not the last one. It's driving me crazy. It spits out
Error using vertcat Dimensions of matrices being concatenated are not consistent.
for that line. Please help. Thanks!
e = [1 1 1 1];
vertcat( 2*(e(2)*e(4) - e(3)*e(1)),2*(e(3)*e(4) + e(2)*e(1)),e(4)^2 + e(1)^2 - e(2)^2 -e(3)^2); % calling vertcat works
[ 2*(e(2)*e(4) - e(3)*e(1)) 2*(e(3)*e(4) + e(2)*e(1)) e(4)^2 + e(1)^2 - e(2)^2 -e(3)^2]; % horizontal works
% subing in works
a = 2*(e(2)*e(4) - e(3)*e(1)); b = 2*(e(3)*e(4) + e(2)*e(1)); c = e(4)^2 + e(1)^2 - e(2)^2 -e(3)^2;
[a; b; c]
% but this doesn't work for some reason...
[ 2*(e(2)*e(4) - e(3)*e(1));2*(e(3)*e(4) + e(2)*e(1));e(4)^2 + e(1)^2 - e(2)^2 -e(3)^2];
Réponse acceptée
Plus de réponses (1)
Sam
Remove all spaces in the crashing line.
[2*(e(2)*e(4)-e(3)*e(1));2*(e(3)*e(4)+e(2)*e(1));e(4)^2+e(1)^2-e(2)^2-e(3)^2]
=
0
4
0
MATLAB was attempting to take in matrix with rows of different lengths because of the way you placed the expressions, spaces, '+' and '-'.
.
Sam
if you find these lines useful would you please mark my answer as Accepted Answer?
To any other reader, if you find this answer of any help please click on the thumbs-up vote link,
thanks in advance for time and attention
John BG
3 commentaires
Sam Swanson
le 13 Jan 2017
Modifié(e) : Sam Swanson
le 13 Jan 2017
Sam, I need the credit points, would you please be so kind to mark my answer as Accepted Answer?
As it's understandable, Mathworks protects the contents of the majority of functions.
There are a few open functions, like fmmod.m and fmdemod.m in the RF Toolbox, but to fix this spaces one may have to contact Mathworks support, report or remove all spaces unless between different matrix elements.
thanks in advance for time and attention, awaiting answer
regards
John BG
Removing all spaces from the code is a bad idea, because it impedes the readability and therefore the debugging. A general rule is to add spaces about binary operators and no space after the unary minus:
x = a + -b;
Nevertheless, I agree that the interpretation of "- 3" and "-3" is ambiguos in Matlab. Allowing the space as a separator between columns and the linebreak for rows was a bad idea from MathWorks. Without this try to be smart, there would not be a problem with spaces around the operators in arrays.
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!