How to convert character matrix into numeric matrix ? Can you share code for that?
2 次查看(过去 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.
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
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!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 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 (한국어)