現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
How to convert character matrix into numeric matrix ? Can you share code for that?
1 回表示 (過去 30 日間)
古いコメントを表示
bavani marimuthu
2017 年 11 月 27 日
I have created a matrix that accepts the text file called pub.txt and content in that file is Hello word alone..and displayed it .
str=fileread('pub.txt')
str =
Hello Bava
Hi Hi
Hi Hi
Now, I want to convert this character matrix into numeric matrix ? Plz help
14 件のコメント
Chafik Zerrouki
2017 年 11 月 27 日
Did you try with str2num() ?
It will Convert character array to numeric array.
bavani marimuthu
2017 年 11 月 27 日
I want it for character matrix into numeric matrix , Not for Array?
Rik
2017 年 11 月 27 日
編集済み: Rik
2017 年 11 月 27 日
Apparently it is time for an important lesson every programmer must learn at some point: RT(F)M (read the manual). There are some examples you can find in the documentation for str2num. (If you're operating on scalars, use str2double instead. Use %#ok to suppress the m-lint warning.)
PS array and matrix are more or less interchangeable terms in Matlab
Adam
2017 年 11 月 27 日
Technically a matrix is 2d and an array is nd in Matlab, but array includes matrix.
bavani marimuthu
2017 年 11 月 27 日
I have created a matrix that accepts the text file called pub.txt code: str=fileread('pub.txt')
Now, I want to convert this character matrix into numeric matrix ? Plz help
Stephen23
2017 年 11 月 27 日
@bavani marimuthu: Guillaume asked you a question. Here it is again:
"What numeric output are you hoping to get..?"
Please show us what numeric output you expect to get from those characters.
Rik
2017 年 11 月 27 日
I can't see a way the string below will result in [100 101 0 0 0 0], so you'll have to explain that.
str = ['Hello Bava';'Hi Hi ';'Hi Hi '];
If your strings contain only numeric values in a char representation (like str='100 101 0 0 0 0';), then using str2num will do the trick.
Stephen23
2017 年 11 月 27 日
"If your strings contain only numeric values in a char representation (like str='100 101 0 0 0 0';), then using str2num will do the trick."
Although using sscanf would be faster and more secure:
>> str = '100 101 0 0 0 0';
>> sscanf(str,'%f')
ans =
100
101
0
0
0
0
bavani marimuthu
2017 年 11 月 28 日
If my .txt file contains the character called 'Hello' .. Then Whether is there any possibilities to convert it into numeric matrix from character matrix which contains the character in it..
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)