Using readxls alldata option
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi,
I am using the readxls to import data into Matlab, the third output of which reads alldata - a subset of my data is as follows -
[332]
[320]
[319]
'ER4'
[744]
[319]
[319]
[772]
[320]
[763]
[734]
[320]
[763]
[744]
'74Y'
'77W'
[772]
'77W'
[346]
[380]
Some entries are double and some strings - I would like the data to be all in the same format (ideally a cell array of strings so I can use the unique function) however I am having some trouble. Does anyone know a way of achieving this?
Many thanks
Jack
댓글 수: 0
채택된 답변
Geoff Hayes
2015년 1월 2일
You could try using cellfun to convert each element of your cell array (the alldata from above) to a string, though I suppose the performance of using this function would depend upon the size of your array. For example,
S = { [332]
[320]
[319]
'ER4'
[744]
[319]
[319]
[772]
[320]
[763]
[734]
[320]
[763]
[744]
'74Y'
'77W'
[772]
'77W'
[346]
[380] };
will create the cell array of numbers and strings. We could then apply the following which will convert each element from a number to a string
V = cellfun(@(x)num2str(x),S,'UniformOutput',false);
Note that for those elements of S that are already strings, then num2str has no effect on that element, and so returns the identical string value. In our case, V becomes
V =
'332'
'320'
'319'
'ER4'
'744'
'319'
'319'
'772'
'320'
'763'
'734'
'320'
'763'
'744'
'74Y'
'77W'
'772'
'77W'
'346'
'380'
and you should be able to apply the unique function to get
unique(V)
ans =
'319'
'320'
'332'
'346'
'380'
'734'
'744'
'74Y'
'763'
'772'
'77W'
'ER4'
Try the above and see what happens!
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!