Get new variable if a cell in a column changes - Matlab
1 view (last 30 days)
Show older comments
Maria
on 25 Jun 2014
Commented: Azzi Abdelmalek
on 26 Jun 2014
I have a cell-type variable X and I would like to have variable X separated in different variables for each different Firm (X(:,1). Meaning, everytime Firm name changes I get a new variable. Example:
X:
Firm
'ABC' 0,5 46 19970224
'ABC' 0,6 29 19970424
'EFD' 0,5 145 19970218
'EFD' 0,5 36 19970206
'GHI' 0,7 9 19971023
'LMN' 0,2 735 19970311
I would like to get:
X1:
'ABC' 0,5 46 19970224
'ABC' 0,6 29 19970424
X2:
'EFD' 0,5 145 19970218
'EFD' 0,5 36 19970206
X3:
'GHI' 0,7 9 19971023
X4:
'LMN' 0,2 735 19970311
Can anyone help? Considering my variable type is 'cell', with both strings and numbers.
0 Comments
Accepted Answer
Azzi Abdelmalek
on 25 Jun 2014
firm={'ABC' 0,5 46 19970224
'ABC' 0,6 29 19970424
'EFD' 0,5 145 19970218
'EFD' 0,5 36 19970206
'GHI' 0,7 9 19971023
'LMN' 0,2 735 19970311}
[a,b,c]=unique(firm(:,1))
out=accumarray(c,(1:numel(c))',[],@(x) {firm(x,:)})
out{1}
out{2}
out{3}
out{4}
5 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!