Problem obtaining minimum negative value in an array

19 Ansichten (letzte 30 Tage)
Omprakash B
Omprakash B am 15 Sep. 2021
Kommentiert: Chunru am 17 Sep. 2021
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 Kommentare
Adam Danz
Adam Danz am 15 Sep. 2021
No error in R2021a.
Any time you're asking about an error, please provide the entire copy-pased error message.
t = linspace(0,15,400);
y = exp(-0.5*t).*cos(2*pi.*t);
m = plot_cos(t, y)
m = -0.7812
function m = plot_cos(t, y)
plot(y,t,'b--')
hold on
[m,~] = min(y);
plot(m,'*r')
hold off
end
Omprakash B
Omprakash B am 16 Sep. 2021
Yes sure. And i was erring at Line no.4. Now I have understood. Thanks.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Chunru
Chunru am 16 Sep. 2021
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 Kommentare
Image Analyst
Image Analyst am 16 Sep. 2021
@Omprakash B, please click the "Accept this answer" link to award @Chunru his reputation points and to let everyone else know it's solved. Thanks in advance.
Chunru
Chunru am 17 Sep. 2021
@Image Analyst Thanks for the kind reminder above. I observed that about 30-40% questioners tend to "forget" click "Accept this anser".

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Contour Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by