- find how many values there are.
- repeat that code for each variable.
Loop through a matrix with multiple elements with the same values
조회 수: 11 (최근 30일)
이전 댓글 표시
Based on this answer given by Cedriv Wannaz, I would like to ask how to generalize the answer. I mean that I know than in the column exist multiple values but I do not know how many they are, but I want to extract the entries as shown in the answer. How do I iterate through the values in order to succeed that?
댓글 수: 0
답변 (1개)
Stephen23
2015년 9월 30일
편집: Stephen23
2015년 9월 30일
The basic steps will be to:
It seems that you are wanting each unique values in the first column of that matrix, in which case you can use unique to get a vector of the unique values:
V = unique(data(:,1));
Then loop over them using a for loop:
for k = numel(V):-1:1
V(k) % value of that loop iteration
... do whatever code with that value
out{k} = ... % save the results
end
Exactly how you save the results (or if they are saved at all) depends on you and what post-processing you want to perform. As you have not told us anything about the post-processing of this data after this step it is difficult to advise on the best way to store the output data.
댓글 수: 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!