Effacer les filtres
Effacer les filtres

Alternatives for str2num function not supported for code generation

5 vues (au cours des 30 derniers jours)
Deepa Maheshvare
Deepa Maheshvare le 4 Oct 2023
Modifié(e) : dpb le 4 Oct 2023
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 commentaires
Stephen23
Stephen23 le 4 Oct 2023
STR2DOUBLE, SSCANF, etc... but which one to select depends largely on the data format.
Deepa Maheshvare
Deepa Maheshvare le 4 Oct 2023
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' }

Connectez-vous pour commenter.

Réponses (1)

dpb
dpb le 4 Oct 2023
Modifié(e) : dpb le 4 Oct 2023
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

Catégories

En savoir plus sur MATLAB Coder dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by