MATLAB Answers

# Matlab onramp problem 44934 plot damped sinusoid

11 views (last 30 days)
James Silk on 7 Aug 2020
Answered: Zhen Yang Chua on 2 Oct 2020 at 13:16
Below is the code I have put in for the above problem but although it seems to plot a graph in line with what the problem asks for it gets the error:
Undefined function 'minus' for input arguments of type 'matlab.graphics.chart.primitive.Line'.
function m = plot_cos(y, t)
m = plot(t, y, '--b')
hold on
[ymin idx] = min(y);
m = plot(t(idx), y(idx), '*r')
hold off
end

#### 0 Comments

Sign in to comment.

### Answers (2)

Jon on 7 Aug 2020
Edited: Jon on 7 Aug 2020
The code that you show seems to be OK. I suspect that one of the arguments (y or t) in the script or function that is calling plot_cos(y,t) is not a vector of double values. Somehow you are passing it the wrong type of argument. Check to see where you assign the variables y and t in the calling program.
Also check to see is the error really coming from the plot_cos(y,t) or do you have some more lines of code after you make the plot, and the error is coming from one of the later calls.
If you are still stuck, please attach your full code that reproduces the problem.

#### 0 Comments

Sign in to comment.

Zhen Yang Chua on 2 Oct 2020 at 13:16
function m = plot_cos(y, t)
m =plot(t,y,'b--')
hold on
[ym idx]=min(y)
m=plot(t(idx),ym,'r*')
hold off
m=ym
end
The problem requested that the minimum is returned as the output for m, your code missed that part.

#### 0 Comments

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!