Alternatives for str2num function not supported for code generation

Hi All,
The following function `str2num` is not supported for code generation.
nodes = str2num(char(G.Nodes.Name));
The nodes names were assigned using the below
G = graph(tail,head);
G.Nodes.Name = cellstr(string(1:height(G.Nodes))');
Other instances where I'm using `str2num`
t = str2num(GraphEdges{edge}(1));
h = str2num(GraphEdges{edge}(2));
Suggestion on an alternate function to str2num that could be used for code generation will be really helpful.

댓글 수: 2

STR2DOUBLE, SSCANF, etc... but which one to select depends largely on the data format.
Thank you for the suggestions.
str2double wors for t = str2num(GraphEdges{edge}(1));
However, I am not sure what has to be used for 'str2num(char(G.Nodes.Name))'
The output of G.Nodes.Name is
{'1' }
{'2' }
{'3' }
{'4' }
{'5' }
{'6' }
{'7' }
{'8' }
{'9' }

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

답변 (1개)

dpb
dpb 2023년 10월 4일
편집: dpb 2023년 10월 4일
G.Nodes.Name=cellstr(num2str([1:9].')); % make example struct
N=str2double(G.Nodes.Name) % convert to numeric
N = 9×1
1 2 3 4 5 6 7 8 9

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품

릴리스

R2023b

질문:

2023년 10월 4일

편집:

dpb
2023년 10월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by