Selecting specific Strings from a cell array
4 views (last 30 days)
Show older comments
Dear all,
I have a dataset with 400000 cells and all cells contain strings. So for example:
Array_A = {'A01','A02','A01','A03','A04','A03'}
I want to go through this cell structure, read the first cell which is 'A01' I want to then save 'A01' to an empty cell array (call it Array_B) and delete all the other instances where 'A01' appears, then I would like to loop again through the same array (i.e., Array_A with all 'A01's deleted), pick the first cell with a string in it 'A02' and then add it to 'Array_B' and delete all instance where 'A02' appears. etc.
In a nutshell, I want to have a list of the different variables I have in the cell array. So in the 400000 cells, I have about 800 different variables which have been repeated many time, I only want the list of 800 different variables in a new array.
So in that process I tried something like this with a smaller array 'raw' of 100 rows:
[r c]=size(raw);
%created an empty array test=cell(r,1);
k = linspace(1,100)
for j=1:100; if strcmp(raw{j,1},'A01'); test{k(1,j),1}='A01'; raw{j,1}=[]; end end
The problem here is that even though all the A01's are deleted from the original array, it places all the 'A01''s in the new array as well. I only want one of them in there.
Could someone help me with this? I look forward to hearing from you at your earliest of convenience.
Sincerely yours' Niraj
0 Comments
Accepted Answer
More Answers (2)
See Also
Categories
Find more on Logical 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!