Selecting specific Strings from a cell array

11 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2013-7-4
Why not use unique() ?

更多回答(2 个)

Niraj Poudel
Niraj Poudel 2013-7-4
Thank you Walter. This might work. I will let you know once I try it out.
Sincerely yours' Niraj

Niraj Poudel
Niraj Poudel 2013-7-4
Hi Walter,
Thank you very much for your suggestion. It worked perfectly.
Sincerely' Niraj

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by