m-file to find elements (text) in an alloy
2 次查看(过去 30 天)
显示 更早的评论
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/357307/image.png)
For example input is ‘Al0.1Co0.25Cu14’ then the code gives output:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/357310/image.jpeg)
If there is any other information you need let me know.
Best
M. Vaghari
2 个评论
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
采纳的回答
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'
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!