How to extract a value/s from a matrix that match with specific rows
1 view (last 30 days)
Show older comments
Hi Friends,
I have a structure matrix (V= 1x6616 struc) as shown in the attched image. I want to sellect the all rows that match with the type '1' in the second colums. I have tried this code but it does not have any result.
for i = 1:numel(V)
C{1, i} = V{1,i}(strcmpi(V{1,i}.type,'1'),:);
end
%%I have tried this one as well, but no result.
C = V({'1'},{'latency','urevent','epoch'});
0 Comments
Accepted Answer
Star Strider
on 28 Jul 2022
One possibility is to use the findgroups function to select the appropriate rows, then use that to index into the data.
type = string(randi(5, 10, 1));
others = rand(10,3);
Everything = [type, others]
[G,ID] = findgroups(Everything(:,1))
Result = Everything(G==1,:)
In the absence of your data, I used the string function to create the first column. This turns ‘Everything’ into strings, however I am certain that this illustrates the concept.
.
2 Comments
More Answers (0)
See Also
Categories
Find more on Characters and Strings 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!