Selecting specific Strings from a cell array

조회 수: 11 (최근 30일)
Niraj Poudel
Niraj Poudel 2013년 7월 4일
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