Using readxls alldata option

5 ビュー (過去 30 日間)
jnaumann
jnaumann 2015 年 1 月 2 日
コメント済み: jnaumann 2015 年 1 月 2 日
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!
  1 件のコメント
jnaumann
jnaumann 2015 年 1 月 2 日
works perfectly thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by