MATLAB Answers

Problem obtaining minimum negative value in an array

조회 수: 2(최근 30일)
Omprakash B
Omprakash B 2021년 9월 15일
댓글: Chunru 2021년 9월 17일
I have written a code to plot the Damped sine wave and to mark a minimum value on the curve.
function m = plot_cos(t, y)
plot(y,t,'b--')
hold on
[m,~] = min(y)
plot(m,'*r')
hold off
end
Input arguments passed:
t = linspace(0,15,400);
y = exp(-0.5*t).*cos(2*pi.*t);
Issue: Not able to plot the minimum value of y. Am I erring in line no. 4??
  댓글 수: 2
Omprakash B
Omprakash B 2021년 9월 16일
Yes sure. And i was erring at Line no.4. Now I have understood. Thanks.

댓글을 달려면 로그인하십시오.

답변(1개)

Chunru
Chunru 2021년 9월 16일
t = linspace(0,15,400);
y = exp(-0.5*t).*cos(2*pi.*t);
plot_cos(t, y)
m = -0.7812
i = 14
ans = -0.7812
% plot t-y or y-t?
function m = plot_cos(t, y)
plot(y,t,'b--')
hold on
[m, i] = min(y) % need to get the location of min
plot(m, t(i),'*r') % plot the min point
hold off
end
  댓글 수: 3
Chunru
Chunru 2021년 9월 17일
@Image Analyst Thanks for the kind reminder above. I observed that about 30-40% questioners tend to "forget" click "Accept this anser".

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by