m-file to find elements (text) in an alloy

조회 수: 1 (최근 30일)
Majid Vaghari
Majid Vaghari 2020년 9월 7일
댓글: Majid Vaghari 2020년 9월 7일
I need a MATLAB m-file to find elements and their ratio in an alloy. The input and output are shown in the below table:
For example input is ‘Al0.1Co0.25Cu14’ then the code gives output:
If there is any other information you need let me know.
Best
M. Vaghari
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 9월 7일
That does not have anything to do with plotting ??
Hint: regexp() . You have a pattern which is a series of non-empty alphabetic characters, followed by a possibly-empty series of non-alphabetic characters
Majid Vaghari
Majid Vaghari 2020년 9월 7일
Thank you.

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

채택된 답변

Stephen23
Stephen23 2020년 9월 7일
>> str = 'Al0.1Co0.25Cu14AaBb';
>> [mat,spl] = regexp(str,'[A-Z][a-z]*','match','split');
>> vec = str2double(spl(2:end));
>> vec(isnan(vec)) = 1
vec =
0.1000 0.2500 14.0000 1.0000 1.0000
>> mat
mat =
'Al' 'Co' 'Cu' 'Aa' 'Bb'
  댓글 수: 1
Majid Vaghari
Majid Vaghari 2020년 9월 7일
Thanks a lot!
It's work!
thank you Mr. Stephen Cobeldick
Best

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by