adding a number to an array

I am trying to create two arrays - one for time, which represents all of the x values for the graph, and one for y, which represents the corresponding y values for each time. The arrays need to be the same length. One section of the graph is a constant, and I am unable to get the y array to be the same length as x. For example, if x is [1 2 3 4 5], the problem I'm running into is that I need y to be [1 1 1 1 1] but can only set the code to be [1, 1].

4 comentarios

David Hill
David Hill el 12 de Sept. de 2019
Please provide the code example. It is unclear to me what your problem is with the array lengths.
Emma
Emma el 12 de Sept. de 2019
Editada: per isakson el 12 de Sept. de 2019
I am creating a function that returns t, a time vector, and e, the corresponding y values of the plot. If plot(t,y) were to be done, it would generate a graph that contained all of the matching t and y values. The graph is given, and the portion that I am currently working on is where y=.5 for an amount of time, t. The code currently is:
tsustain = (10+1/fs):1/fs:20;
t = [t, tsustain];
e = [e, s];
Where the start value t is from a previous section. I need e to be [e s s s s s], where the total length of e will then match the length of t.
Walter Roberson
Walter Roberson el 12 de Sept. de 2019
e = [e, repmat(s, 1, length(tsustain))]
Emma
Emma el 12 de Sept. de 2019
Thank you!

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 12 de Sept. de 2019

Comentada:

el 12 de Sept. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by