What is the difference between [v' 1] and [v', 1]?
2 views (last 30 days)
Show older comments
I come across these two notations and still cannot distinguish them.
v' is the transpose of v. The first notation [v' 1] will be transpose of v' with column of 1 at the end.
Is [v', 1] related to matrix indexing? Please help.
0 Comments
Accepted Answer
KSSV
on 15 Oct 2021
v = rand(3,1) ;
[v' 1]
[v',1]
That is nothing but vector v is increased by one element at the end and the value is 1.
0 Comments
More Answers (1)
Walter Roberson
on 15 Oct 2021
v = ((1:3) -(2:4)*1i).'
[v' 1]
[v', 1]
You can see that even for complex numbers, [v' 1] and [v', 1] produce the same results. This is not an accident.
The difference between [v' 1] and [v', 1] is that the version with the comma reduces the risk of values accidentally being treated as subtraction:
[v' -1]
[v', 1]
[v' - 1]
[v', - 1]
Notice that the [v' - 1] form was treated as subtraction of 1, but [v' -1] and [v', -1] and [v', - 1] forms treated the -1 or - 1 as a negative 1 rather than a subtraction.
The rule is:
If the last thing you saw was a delimiter or a delimiter followed by whitespace, then + and - following are the "unary plus" and "unary minus" operators, no matter whether they are followed by whitespace or not.
If the last thing you saw was an expression without delimiter, or whitespace after an expression without delimiter, then + followed by whitespace is addition, and - followed by whitespace is subtraction, but + followed without whitespace is unary plus, and - followed without whitespace is unary minus.
% U U S A
[1 +1 -1 1 - 1 + 2]
U here indicating unary operator, S indicating subtraction, A indicating addition. Compare to
[1, +1, -1, 1, - 1, + 2]
So the comma help prevent accidental interpretation as subtraction or addition
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!