Scilab syntax: How to transpose and reshape without the use of an intermediate variable?
15,943
Although the transpose operator doesn't seem to have a keyword equivalent the (:)
syntax does: matrix.
So the equivalent of A(:)
would be matrix(A,1,-1)
such that you're reshaping to 1 column and 'however many' rows (the -1 argument). Thus if you feed A'
into that you get the row vector in the desired order
-->matrix(A',1,-1)
ans =
1. 2. 3. 4. 5. 6.
This works with the conjugate transpose operator too (A.'
).
Author by
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
Lets use the matrix A as an example:
-->A = [1 2 3; 4 5 6] A = 1. 2. 3. 4. 5. 6.
I can transpose this matrix:
-->A' ans = 1. 4. 2. 5. 3. 6.
...and I can reshape this matrix into a single column:
-->A(:) ans = 1. 4. 2. 5. 3. 6.
...but I cannot transpose and reshape in a single line or without using a intermediate variable:
-->A'(:) !--error 276 Missing operator, comma, or semicolon. -->B = A'; B(:) ans = 1. 2. 3. 4. 5. 6.
Is there a way to accomplish this without the intermediate variable?
-
Admin over 11 yearsThanks, this is how I ended up coding it, too. I still think there must be a 'better' way (less typing, clearer, not with a workaround feeling).