## Math operations with Imported Data from Text

### fert (view profile)

on 7 Feb 2016
Latest activity Commented on by fert

### fert (view profile)

on 7 Feb 2016
Accepted Answer by Walter Roberson

### Walter Roberson (view profile)

I have imported a text file. When I multiply the cells such as, filename(4,7)*filename(6,5); I get an error. I extracted data as cells since it includes both strings and the numbers. How can I handle this problem?

### Walter Roberson (view profile)

2016 年 2 月 7 日
採用された回答

filename{4,7}*filename{6,5}

fert

### fert (view profile)

2016 年 2 月 7 日
size : 1 * 8 and 1 * 7
class: char and char .
It is strange because when I call one of these values to the command, they give the answer as numbers, but here seem as chars.
The other thing is I don't understand why sizes are different. These cells I call only contain a number.
I have done the import with "cell array" instead of "column vectors", "numeric matrix", or "table"; since it contains both numbers and strings. Could it be because of that?
Walter Roberson

### Walter Roberson (view profile)

2016 年 2 月 7 日
You cannot multiply strings. If you have strings that represent numbers then you need to convert them to numbers before you can work with them. A good way to do that is with str2double()
numeric_filename = str2double(filename);
numeric_filename(4,7) * numeric_filename(6,5)
Notice that this is a numeric array instead of a cell array. The entries that are not understandable as representing numbers will be converted into NaN . (It is sometimes surprising what can be converted into numbers... the letters 'd', 'D', 'e', 'E', 'i', 'I', 'j' and 'J' can all end up being interpreted as part of numbers.)
fert

### fert (view profile)

2016 年 2 月 7 日
Thank you very much for your time, I will try this.