Program for MAX & MIN
Ältere Kommentare anzeigen
This code not giving me maximum,minimum value and index that i am looking for. so i want the 3 maximum and 2 minimum values and index that will be same as plot figure.
and this new code will true for any TT array
close all;
TT = [ 50 0 136 30 80 59 59 229 59 20 152 69 72 120 36 233 2 8 52 156 20 30 119 5 101 177 50 25 209 33 96 67 68 125 67 100 127 83 95 88];
NN = 1:1:40;
figure (1)
stem (NN,TT);
D = movmean (TT,5);
figure (2)
plot (NN,D)
%% threeMax and twoMin will be used to store the max and min values
threeMax = zeros(1,3);
twoMin = 100*ones(1,2);
max1index = 0;
max2index = 0;
max3index = 0;
min1index = 0;
min2index = 0;
%% loop logic to rank largest 3 elements in descending order
for i = 1:1:length(D)
if D(i) > threeMax(1)
threeMax(3) = threeMax(2);
max3index = max2index;
threeMax(2) = threeMax(1);
max2index = max1index;
threeMax(1) = D(i);
max1index = i;
elseif D(i) > threeMax(2)
threeMax(3) = threeMax(2);
max3index = max2index;
threeMax(2) = D(i);
max2index = i;
elseif D(i) > threeMax(3)
threeMax(3) = D(i);
max3index = i;
else
end
end
%% loop logic to locate the 2 smallest nonzero elements
for i = 1:1:length(D)
if D(i) < twoMin(1) && D(i) > 0
twoMin(1) = D(i);
min1index = i;
elseif D(i) < twoMin(2) && D(i) > 0
twoMin(2) = D(i);
min2index = i;
else
end
end
PLEASE HELP ME ASAP - PLEASE USE MY PROGRAM THAT I PROVIDED
AND ALSO SEE EXAMPLE FIGURE THAT I UPLODED
THANK YOU
7 Kommentare
Star Strider
am 25 Okt. 2019
Help you with what?
You never asked a Question, so no Answer is possible!
DP
am 25 Okt. 2019
DP
am 25 Okt. 2019
DP
am 25 Okt. 2019
John D'Errico
am 25 Okt. 2019
A little demanding are you? Yes, sir! We will immediately assign our best person to this task, because we know you are important, and we cannot allow you to have to learn MATLAB yourself.
Think of it like this: when you ask a confusing or ambiguous question, expect people to be unwilling to jump in there and offer help. Odds are they will guess wrong on any assumptions they need to make because you were not explicit in what you are asking. Then they will need to make multiple responses. Sorry, but for me, its not worth the hassle, and that will be true for many others. Remember that we are purely VOLUNTEERS on Answers.
Also, if you demand that people answer you immediately, then expect people to be a little leery of responding too.
So if you want help, then make your question CLEAR. And RELAX. Someone may decide to answer your question, or not, and it may take longer than you want. Remember that Answers is a free site. If you insist on an immediate answer, then you might consider paying someone for the service. I'm sure there are people who would be willing to write your code for you for the correct fee.
Star Strider
am 25 Okt. 2019
@John D’Errico — Thank you!
Rena Berman
am 12 Dez. 2019
(Answers Dev) Restored edit
Antworten (2)
David Hill
am 26 Okt. 2019
Your plot is not marking the three maximum values. If you did want the maximum values and the minum values in between, then you could just force it.
[M1,i1]=max(TT);
TT(i1)=nan;
[M2,i2]=max(TT);
TT(i2)=nan;
[M3,i3]=max(TT);
m=sort([i1,i2,i3]);
[m1,i4]=min(TT(m(1):m(2)));
[m2,i5]=min(TT(m2:end));
Image Analyst
am 28 Okt. 2019
0 Stimmen
It's not clear how those particular locations were chosen. My best guess is that you are trying to find the peaks and valleys of a smoothed version of your data. So I'd try movmean() or sgolayfilt() followed by findpeaks().
Kategorien
Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!