Using readxls alldata option

7 次查看(过去 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

采纳的回答

Geoff Hayes
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 CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by