- find how many values there are.
- repeat that code for each variable.
Loop through a matrix with multiple elements with the same values
2 次查看(过去 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!