MATLAB Answers

Concatenate signals ( sine wave and a line )

46 views (last 30 days)
Bianca Ivan
Bianca Ivan on 1 Dec 2020
Commented: Bianca Ivan on 1 Dec 2020
How can I concatenate a sine wave and a line? I tried something and the error was : Dimensions of matrices being concatenated are not consistent.

  4 Comments

Show 1 older comment
Bianca Ivan
Bianca Ivan on 1 Dec 2020
t = [0:0.1:2*pi]
a = sin(t);
X = [0.1,0.4];
Y = [0.1,0.1];
total=[a; X; Y];
plot(total)
i tried this code
Timo Dietz
Timo Dietz on 1 Dec 2020
Not sure what you want to plot. A sine wave with a line at its end?

Sign in to comment.

Answers (3)

KALYAN ACHARJYA
KALYAN ACHARJYA on 1 Dec 2020
Edited: KALYAN ACHARJYA on 1 Dec 2020
total=[a X Y];
Here "a" is row data, so you must have row-wise (horizontally) concatenate

  0 Comments

Sign in to comment.


Star Strider
Star Strider on 1 Dec 2020
You are attempthing to vertically concatenate them.
Use commas (,) instead fo semicolons(;) and it will work. Commas horizontally concatenate and semicolons vertically concatenate.

  0 Comments

Sign in to comment.


Timo Dietz
Timo Dietz on 1 Dec 2020
I guess you want to add a X/Y line after the sine wave, right?
In this case you have to concatenate X + t and Y + a in order to have a new total X and total Y vector.
Looks weird but is this what you wanted to have: plot([t X], [a Y])

  1 Comment

Bianca Ivan
Bianca Ivan on 1 Dec 2020
Thank you! I have to change the vectors values

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!