フィルターのクリア

Non-numeric matrix to string

4 ビュー (過去 30 日間)
Diego Tasso
Diego Tasso 2012 年 6 月 13 日
Hi i am trying to import an excel file to matlab and convert the matrix crated into a string in order for me to use sscanf to format the file to show certain information. However this matrix contains data such as " 34WP01"....any ideas? I tried using the mat2str function but its telling me the matrix must be numeric.

採用された回答

Geoff
Geoff 2012 年 6 月 13 日
It's not a matrix. It's a cell array.
You can try converting the whole thing to strings with something like:
[M{:}]
Where M is your array... But that joins them with no spaces... How about adding a space to each entry maybe:
Msp = cellfun(@(x) [x,' '], x, 'uni', 0);
Mstr = [Msp{:}]
Bit hacky, I know... But it might work for you.
Otherwise maybe you want to use regexp. It'll work on cell arrays of strings. Then you probably won't require sscanf.
  2 件のコメント
Walter Roberson
Walter Roberson 2012 年 6 月 13 日
With spaces between:
Mt = strcat(M(:).', {' '});
joined_string = deblank([Mt{:}]);
This does make assumptions about how you want them joined. It would not be suitable (as-is) for joining row-by-row in a cell array.
Diego Tasso
Diego Tasso 2012 年 6 月 14 日
Thanks Geoff and Walter; I tried doing what you said using the deblank and cellfun functions you suggested however I found it more useful to use the regexp function; did not know it existed.Thanks again !

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by