Finding minima using if and for loops
    조회 수: 11 (최근 30일)
  
       이전 댓글 표시
    
I have a column of data and I want to make a script that utilizes for loops and if constructs 
for example
12
4
5
23
63
57
23
6
34
In this set, the minima would be 4 and 6 
채택된 답변
  BOB MATHEW SYJI
      
 2020년 9월 16일
        
      편집: BOB MATHEW SYJI
      
 2020년 9월 16일
  
      Hope this helps. Vector y returns the minimum values of vector A
A=[12; 4; 5; 23; 63; 57; 23; 6; 34];
a=A';
d=[diff(a) 0];
c=[];
for i=1:(length(d)-1)
    if d(i)*d(i+1)<0&&d(i+1)>0
        c=[c (i+1)];
    end
end
for j=1:length(c)
    y(j)=a(c(j));
end
댓글 수: 2
  Star Strider
      
      
 2020년 9월 16일
				This is homework.  
We have a policy of providing only hints for homework.  It is not appropriate to provide complete solutions.  
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


