-2

I need to know what the single quote mark is at the end of the first line of this code . What is the meaning of it .?

X = linspace(0,2*pi,50)';
Y = [cos(X), 0.5*sin(X)];
stem(Y)

when I remove I see a single color two functions plotted coming after the other , when I use it , I see what exactly I want to see . But what is it ? When should I use it ?

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147

1 Answers1

-2

The single quote mark is transposing the vector. That means, a row-vector becomes a column-vector and vice versa.

drops
  • 1,524
  • 1
  • 11
  • 20
  • 1
    A question as basic as this likely has a duplicate. You should look for duplicates and flag them instead of answering. – Pranav Hosangadi Jul 31 '20 at 16:06
  • 3
    Also, it's not transpose. It's complex-conjugate transpose – Luis Mendo Jul 31 '20 at 16:26
  • Why do we need the complex conjugate transpose in this code then ? – Burak Günay Jul 31 '20 at 17:31
  • @BurakGünay Many people tend to use `'` for transpose. With non-complex numbers that obviously works, but I believe it's a [bad idea](https://stackoverflow.com/q/25150027/2586922) – Luis Mendo Jul 31 '20 at 18:47
  • No I mean why would we need this transpose in the given code piece ? Why does it help me to view two different color of plots (which is I need but why ?) – Burak Günay Jul 31 '20 at 18:52
  • 1
    @BurakGünay, `cos(X)` and `sin(X)` have the same shape as `X`. Y is from stacking these two results horizontally (`[cos(X), 0.5*sin(X)]`). if `X` is of shape `1xN` (no transpose), then Y has the shape `1x2N`, so `stem(Y)` plots a single series with `2N` points. OTOH, if X is transposed (shape = `Nx1`), Y has the shape `Nx2`, and `stem(Y)` plots two series with `N` points, which is what you expect. – Pranav Hosangadi Jul 31 '20 at 19:06