Problem 44934. Plot Damped Sinusoid
Solution Stats
Problem Comments

15 Comments
hi, I do not understand why when a submit my code i get an error, it said "check data".
Mohamed, the check plotted data error suggests that the data you are plotting in the plot command does not match the data you are expected to plot i.e. your y and m variables. The red star marker must be on the minimum value of any given input signal y.
I kept getting an error plotting star with both 'p' and 'h', it only accepted the code when I changed it to an asterisk '*'. please modify the question to made it more understandable.
Thanks Ian for pointing out the error. I have updated the description to use the appropriate name for the marker.
Even without plotting the graph ploblem is getting solved and accepted. So, there is no point in comparing our solution witht the leading solution!
Omkar Thanks for pointing out the issue with the test suite. I have modified messages to errors when the solution has no plot or too many plots. The solutions will be rescored.
I put this code in my desktop Matlab and the plot looks fine, but Cody says it's wrong. Can someone give me a hint?
function plot_cos(y, t)
t = linspace(0,15,400);
[val,i]=min(exp(0.5*t).*cos(2*pi.*t));
plot(t,(exp(0.5*t).*cos(2*pi.*t)),'b',t(i),val,'r*')
end
my solution is accepted but the feedback is broken. I get this message.
"We're sorry, but something went wrong.We've been notified about this issue and we'll take a look at it shortly."
I received the same msg as Jimmy although my code was accepted: "We're sorry, but something went wrong.We've been notified about this issue and we'll take a look at it shortly."
I have tried with below command,but its not working.Kindly suggest some hints.
function m = plot_cos(y, t)
plot(m(min),"r * ") ;
end
Good problem
I has a problem here and i dont understand its mean
Undefined function 'minus' for input arguments of type 'matlab.graphics.chart.primitive.Line'. Error in Test1 (line 6) assert(abs(m  (0.781239288889930)) <= 1e4)
a very challenging and good problem
This problem description is problematic, and do is the test suite code as many have pointed out.
tip/hint: don't use 'scatter' function to plot the minimum asterisk marker as I did, test suite only accepts 'plot' for a a dum(b)p reason (pun intended *)
Took me forever but I finally got it :)
Solution Comments

1 Comment
b and r*

1 Comment
I would rate it as an easy task to solve, but the problem description is a bit clumsy, for example m is a minimum return value, so I rated medium not for solving difficulty, but understanding description difficulty :)

1 Comment
the leading solution is incorrect...the minimum value of y does not correspond to a time value of 1, but corresponds to a value of 0.4887...plot the leading solution to confirm.

1 Comment
nice Problem [m,pos] = min(X)

1 Comment
This solution previously submitted passes the tests but is incorrect as it does not find the associated t value for m.

1 Comment
not bad

3 Comments
you should be really careful about the description of the question, for example, i failed a few times for not notice i should use "m" to denotes the min.
This comment saved me a big headache. No idea what they wanted from m.
thanks a lot for the hint, it really matters

1 Comment
The test suite should also verify that the red dot has been placed correctly. In fact, even if the abscissa of the point in question is taken wrong, the wrong code is accepted as a solution.

1 Comment
There is a bug on the verification, the minimum value with the lowest size solution is not plotted at the correct time value.

1 Comment
function m = plot_cos(y, t)
[m,pos] = min(y);
plot(t,y,'b',t(pos),m,'r*');

3 Comments
function m = plot_cos(y, t)
[m,idx]=min(y);
t_m=t(idx);
plot(y,t,'b',m,t_m,'r*')
end
why doesn't it work? It gives the error "Check plotted data" but my data works just fine on my pc. Any ideas on why it doesn't accept my solution?
Just change the order in plotting, i.e,
plot(t,y,'b',t_m,m,'r*')
since plot(x,y) is main function.
x>t and y>y
use hold on after first plot

1 Comment
I have submitted the code which is working exactly as required in matlab script but cody is not accepting my solution.Please help

1 Comment
Why is this program failing?
function m = plot_cos(y, t)
j = size(y);
k = zeros(1,j(2));
a = k  y;
b = max(a);
k = find(a==b);
m = b;
plot(t,y,'',t(k),m,'r*');
end

3 Comments
cool,didn't know the ''1,ans'',it's a great way to use this function.
but why "1", didn't understand
Maybe this test doesn't check XData so "1" is valid for the solution
assert(isequal([h.YData],[m, y]), 'Check plotted data')
Nice code

2 Comments
There seems to be a bug in the test suite. This is passed as a valid solution, although the minimum point is not correctly marked.
To give a correct result, line 3 should read:
plot(t,y,'b',t(im),m,'r*');
absolutely, but the thing is how other peers were able to submit

5 Comments
Undefined function 'minus' for input arguments of type 'matlab.graphics.chart.primitive.Line'.
Error in Test1 (line 5)
assert(abs(m  (0.781239288889930)) <= 1e4)
i cant understand this error the code just works fine on matlab
function m = plot_cos(y, t)
[val,i]=min(y);
m=plot(t,y,'b',t(i),val,'r*');
end
function m = plot_cos(y, t)
[val,i]=min(y);
m=plot(t,y,'b',t(i),val,'r*');
end
this code works fine on pc but just got error on test
Undefined function 'minus' for input arguments of type 'matlab.graphics.chart.primitive.Line'.
Error in Test1 (line 5)
assert(abs(m  (0.781239288889930)) );
end
Hi Ali, this is because the output m is expected to contain the minimum value of the input y, not a handle to the plot.
Hope that helps.
function m = plot_cos(y, t)
[m,idx]=min(y);
t_m=t(idx);
plot(t,y,'b',t_m,m,'r*')
end
:D
I have the same problem lol, and thanks for pointing out the blind spot!

1 Comment
the test syntax in line 5 is wrong

2 Comments
So we don't need to plot the graph?
That is correct. The problem description is one thing. The test suite is another. The test suite explicitly accommodates solutions that do not plot the graph. Since this took extra effort to incorporate into the test suite, I view my solution as fully within the scope and intent of this problem.

2 Comments
It works perfectly fine on PC.
Thanks Paresh. Your approach is a valid solution that the tests were not designed to evaluate previously. I have now modified the tests to pass this alternative approach. However, there are two other issues with this solution, which you will have to resolve: 1. The color 'b' expected for the line is not the same as the default blue color the MATLAB uses. 2. The output is expected to be the minimum value of y, not a handle to the plot.
I have also added appropriate messages for the tests. Thanks again!

3 Comments
why it is failing..i dont understand..it gives no indication why assertions have failed
Hi Asif, the output from the function is expected to be only the minimum value of vector y; whereas your code returns both  the minimum value of y and also the corresponding t. This is causing the last test to fail. I will modify the tests to make it clearer. You should pass the tests if you set m = ymin
thank u

1 Comment
Hey any chance i could get a little help with 44934 Plot Damped Sinusoid

3 Comments
I don't understand what is wrong. The output below states that the assertion failed on test 2, but it gives no indication of which assertion failed or what the cause was. I plotted this on my matlab and it produced the plot shown in the problem statement. Please clarify what the error is in my code.
Andrew, I suspect that this is failing the second test because the new plot lines are being plotted over the previous plot (from test 1). It is always a good practice to use 'hold off' (here and in MATLAB, generally) to stop plotting over old plots. Having said that, I will consider adding a 'figure' command to the tests, since Cody does not display the plots and it is difficult to debug this particular problem without seeing the plots.
Pooja, you were correct. Adding the hold off command to the end of the code allowed it to submit successfully. Thank you.
Problem Recent Solvers6278
Suggested Problems

Determine whether a vector is monotonically increasing
16643 Solvers

Sum of diagonal of a square matrix
1479 Solvers

487 Solvers

393 Solvers

403 Solvers
More from this Author13
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!