How to repeat the value of y to have the same length as x?

1 view (last 30 days)
I need to add a text to a plot.
text(x,max(E),'it is inf')
and the length of x can be more than one. so I will get the error because the length of x and y (max(E)) are not matching. I want to form y by repeating max(E) with the size of x. For example if the size of x is 4, then I wan to have y=[max(E),max(E),max(E),max(E)]. What is the shortest way to do it?
I want to avoid for loop as much as possible.

Answers (1)

madhan ravi
madhan ravi on 6 Sep 2019
y = repmat(max(E),size(x))

Community Treasure Hunt

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

Start Hunting!