フィルターのクリア

convert a string vector to a vector of numbers

5 ビュー (過去 30 日間)
googo
googo 2013 年 4 月 16 日
Hello,
suppose I have a vector of string [1 2 3 4] and i want to change it to a vector of nmbers to do a numeric caculations, How can I do it? Thank's!
  2 件のコメント
Walter Roberson
Walter Roberson 2013 年 4 月 16 日
Are the '[' and ']' in the string? Are the numbers only integers or possibly floating point ?
googo
googo 2013 年 4 月 16 日
string=['1' '2' '3' '4'] and I want to change it to : a = [1 2 3 4]

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

回答 (1 件)

Friedrich
Friedrich 2013 年 4 月 16 日
編集済み: Friedrich 2013 年 4 月 16 日
Hi,
as long there are no [] in the string use textscan:
textscan('1 2 3 4 6.3','%f','delimiter',' ')
In the case there are use strrep to remove the [ or ] before calling textscan.
  8 件のコメント
Walter Roberson
Walter Roberson 2013 年 4 月 16 日
You have
t(i,n+1)=num2str(c);
the destination t(i,n+1) is a single character. The number 10 and upwards require two (or more) characters to represent as a string. Therefore if c reached 10 (occurrences) the code would fail. This suggests that you have a code design problem.
googo
googo 2013 年 4 月 16 日
Thank you... I'll try to find a way to fix it..

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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by