Extract individual numbers from a list
    조회 수: 4 (최근 30일)
  
       이전 댓글 표시
    
Hi there, As shown below I have a shortened version of a list of values belonging to p.
p =
     2
     3
     3
     3
     4
     3
     3
     4
     3
     3
     4
What I would like to do is extract each of the numbers from this list one by one. I know that I can make use of the functions below in order to extract each value one by one. However this would make for a very long code. Is there a way that this can be done in type of loop?
 z = p(1,1)
 z2 = p(2,1)
 z3 = p(3,1)
댓글 수: 0
채택된 답변
  Jos (10584)
      
      
 2016년 5월 16일
        Do not do this!
It is the contents of a variable that should change, not the name of the variable itself. An example in real life, you hardly ever need to buy a new box if you buy new cookies. In matlab you can use indexing in your list to get a specific element:
MyBoxes = [10 11 12 13] ; % list of cookie types in each box
BoxToUse = 3 
CurrentCookie = MyBoxes(BoxToUse)
댓글 수: 0
추가 답변 (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!

