How can i separate the content of the structure array and make two new arrays?

1 view (last 30 days)
I have a list of 1000 events that belong to boys and girls. Now i want two separate arrays with event numbers (separated according to gender). one with the list of all boys events another with a list of girls event.
for n=[1:1000]
if Event(n)="boys day out"
then n should belong to a new array, say B.
else if Event(n)="girls day out"
then n should belong to a new array, say G.
I want two seperate arrays B and G to give me the list of boys events and girls events respectively.
How do I do this ? How do I define B and G ?

Answers (1)

Image Analyst
Image Analyst on 16 Oct 2020
This will do it:
Event = ["boys day out";
"girls day out" ;
"girls day out" ;
"boys day out";
"boys day out";
"girls day out" ;
"girls day out"]
allRows = 1 : length(Event)
rows = strfind(Event, 'boys')
boyRows = setdiff(allRows, find(cellfun(@isempty, rows)))
rows = strfind(Event, 'girls')
girlRows = setdiff(allRows, find(cellfun(@isempty, rows)))

Categories

Find more on Characters and Strings in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!