Error in using eval with num2str
古いコメントを表示
I want to rename a variable within the loop by using matlab standard eval and num2str functions.
Here is the line of the code I've written to do so:
eval(['DTU_10MW_RWT_s' num2str(seed) '_' num2str(wind) '_' num2str(I) '_' num2str(derate) ' = DTU10MWRWT;'])
When seed,wind, I, derate take integer values, the function gives what I want, but when these variables take rational noninteger values, it gives me this error:
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
Any feedback is very much appreciated.
1 件のコメント
"Any feedback is very much appreciated."
In general, will converting "rational noninteger values" to text produce valid variable names? (hint: no).
For example, is the text "1.23e-4" part of a valid variable name? (hint: no, the dot and minus are not permitted).
Your data design forces you into writing complex, buggy, slow, fragile, inefficient code.
Solution: do not force meta-data into variable names.
Meta-data is data. Data should be stored in variables, not in variable names.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Variables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!