How to extract rows which contains specific values in each row, then automatically repeat the process for a range.
Show older comments
i have a table of values imported from excel where one of the columns has a range of 0 to 8 . where there are several rows associated to each number through 0 and 8 . how can i extract the rows that have 0 in that column to do calulations , then repeat the proccess with the rows that have 1 in the same column and so on. would it require a loop ? how would the code be setup ?
as seen below all the results are te same because the calulations are being done to the whole column rather than the specified ones in red ( which should be equal to no_avg)

4 Comments
Bob Thompson
on 10 Jun 2019
I would anticipate using a loop for this, but before we can talk about how we need to know how you have your data contained within matlab. You mentioned having an excel document, but you screen shot seems to indicate you are looking at iterating T as a single set of data multiple times.
Nasir
on 10 Jun 2019
Bob Thompson
on 10 Jun 2019
Are you running into a specific error message? If so, please post the entire error message.
If not, please explain why you think the code is not doing what you want it to. What results are you seeing, and how do they differ from what you would expect?
Accepted Answer
More Answers (1)
Bob Thompson
on 10 Jun 2019
0 votes
Without direct access to your data I cannot give you a perfect solution to your data, so what I put here will likely take some finessing to get it to work perfectly with your dataset. From what I understand you're mostly having trouble with identifing and selecting the data with specific values, as opposed to calculating the mean, or other calculations you want to make. Therefore, I am going to focus on that part.
As I mentioned, I think a loop will be simplest here.
range = unique(t1{:,{'x0102ThrottleNotch'}}); % Identify different values, incase they change
for i = 1:length(range)
r = find(t1{:,{'x0102ThrottleNotch'}}==range(i)); % Return rows for corresponding throttle notch value
... % Do you other calculations for each throttle notch here
end
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!