フィルターのクリア

Convert 'str' to 'number'

2 ビュー (過去 30 日間)
armin m
armin m 2021 年 7 月 6 日
コメント済み: armin m 2021 年 7 月 6 日
Hi. I have 'str' like 'P12teta4'i want write a code which take first alphabet (here P), first and second number (here 1 and 2) second word (here teta) and third number (here 4). For example: code we have: ...... .. ..... Result: a=P, b=1, c=2, d=teta, E=4. Tnx

回答 (1 件)

Jan
Jan 2021 年 7 月 6 日
編集済み: Jan 2021 年 7 月 6 日
str = 'P12teta4';
a = str(1);
b = sscanf(str(2), '%d');
c = sscanf(str(3), '%d');
ind = find(isstrprop(str(4:end), 'digit'), 1);
d = str(4:2+ind);
e = sscanf(str(3+ind : end), '%d');
% This crops the trailing number:
List = textscan(str, '%c%1d%1d%[^0123456789]s%d')
  1 件のコメント
armin m
armin m 2021 年 7 月 6 日
If P be a matrix P=[5 78 9] so a(3) should show 9. But it seems a = str(1) > here is just alphabet a=P and after that is not a matrix. I want it then show that matrix.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by