Math operations with Imported Data from Text

조회 수: 5 (최근 30일)
fert
fert 2016년 2월 7일
댓글: fert 2016년 2월 7일
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
Walter Roberson 2016년 2월 7일
filename{4,7}*filename{6,5}
  댓글 수: 5
Walter Roberson
Walter Roberson 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 2016년 2월 7일
Thank you very much for your time, I will try this.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by