You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to convert character matrix into numeric matrix ? Can you share code for that?
2 views (last 30 days)
Show older comments
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 Comments
Chafik Zerrouki
on 27 Nov 2017
Did you try with str2num() ?
It will Convert character array to numeric array.
Rik
on 27 Nov 2017
Edited: Rik
on 27 Nov 2017
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
on 27 Nov 2017
Technically a matrix is 2d and an array is nd in Matlab, but array includes matrix.
bavani marimuthu
on 27 Nov 2017
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
on 27 Nov 2017
@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
on 27 Nov 2017
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
on 27 Nov 2017
"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
on 28 Nov 2017
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..
Answers (0)
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)