필터 지우기
필터 지우기

Using unique fuction on cell array

조회 수: 3 (최근 30일)
Stephan Richtering
Stephan Richtering 2016년 1월 13일
댓글: dpb 2016년 1월 14일
Hello,
This is following up on a previous post adding two cells together. http://www.mathworks.com/matlabcentral/answers/263633-combining-to-two-cells
The reason I this is because I couldn't use the unique function unless it was a cell array of string. So I changed the one column. However, I can't apply this to the whole table and I want to use the function X=unique(X,'stable'). So in the picture attached it would remove second of the two highlighted rows. The unique function doesn't work as there is a mix of cell types.
ALTERNATIVE:
Focus on three columns where one is a mixture of string/number, number and date (first three columns in the sample excel sheet).
For the string/number I want to use something similar to numstr(). From my previous question I probably create another column using the for loop
for n = 1:length(p)
A(n) = {[num2str(p{n,1}),k{n,1}]};
end
and then for the number I would use the suggestion from dpb using cellmat. For dates unique works fine.
Putting them together I would find the unique indices
Thanks, Stephan
  댓글 수: 9
Stephan Richtering
Stephan Richtering 2016년 1월 14일
I would like to simplify the data! But I think the data is inputted by various sources and is not something that can be standardized. Many of them are a mixture of numbers and string in the format of 1,2...x 'ND'
Stephan Richtering
Stephan Richtering 2016년 1월 14일
편집: Stephan Richtering 2016년 1월 14일
Edited the question as given your inputs it may be easier to focus on the data types I know. Not the exact solution but given the inconsistency in the data it probably it is the easiest to implement in Matlab

댓글을 달려면 로그인하십시오.

답변 (1개)

dpb
dpb 2016년 1월 13일
>> ccc % a sample cell array similar to shown...
ccc =
'13,14' [10700]
'13,14' [ 0]
'123' [ 200]
'123' [ 200]
>> [~,ia]=unique(cell2mat(ccc(:,2)),'stable') % get the unique indices from the 2nd column
ia =
1
2
3
>> ccc(ia,:) % show the result
ans =
'13,14' [10700]
'13,14' [ 0]
'123' [ 200]
>>
To pare the table simply reassign --
ccc=ccc(ia,:);
  댓글 수: 4
Stephan Richtering
Stephan Richtering 2016년 1월 14일
Well the data structure may vary. It may be a string or a cell i.e. there are no restrictions of the input unless it is a date.
I can upload a data file but the data would not fully encompass all possibilities. I just want to simple remove duplicates as you can do in excel which doesn't differentiate between the different cell types (or maybe it does its own conversion)
dpb
dpb 2016년 1월 14일
I believe internally for that operation Excel does the comparison to each column individually behind the scenes and then combines those logical results. If your data really are so ill-formed as you say and you can't (or won't???) clean it up in the process of importing it to make it more manageable, then I'd posit the above is the only option you've left yourself.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by