Why don't I get a matrix of colors instead of a vector?

When I create four random colors, a and b show up as a row of four swatches
But when I try to create a matrix [a;b], figuring four over and under, all I get is a vector row of eight swatches

What am I doing wrong?

a = [RGB(rand(),rand(),rand()) for x in 1:4]
b = [RGB(rand(),rand(),rand()) for x in 1:4]

[a;b]

image

Interesting. I also want to know, but I would’ve done

vcat(a, b)

or

transpose([a b])

or

reshape([a;b], 2, :)

This is a matter of Julia’s design, not a problem of colors.

julia> a = [1, 2, 3, 4]; b = [5, 6, 7, 8];

julia> [a; b]
8-element Vector{Int64}:
 1
 2
 3
 4
 5
 6
 7
 8

However, I don’t think it is useful to arrange the color swatches vertically.

1 Like

To get a 2-row matrix from two vectors of reals one can do: [a'; b'] for more general case you could use: permutedims([a b])

1 Like

Thanks. What is the apostrophe for? I haven’t seen that usage.

Check the help:

help?>  '
  A'
  adjoint(A)

  Lazy adjoint (conjugate transposition). Note that adjoint is applied recursively to elements.

  For number types, adjoint returns the complex conjugate, and therefore it is equivalent to the identity function for real    
  numbers.

  This operation is intended for linear algebra usage - for general data manipulation see permutedims.
1 Like