Filter löschen
Filter löschen

Using readxls alldata option

7 Ansichten (letzte 30 Tage)
jnaumann
jnaumann am 2 Jan. 2015
Kommentiert: jnaumann am 2 Jan. 2015
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

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 2 Jan. 2015
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!

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by