Azzera filtri
Azzera filtri

How to access table with eval?

6 visualizzazioni (ultimi 30 giorni)
Y. J.
Y. J. il 25 Lug 2018
Risposto: Jan il 25 Lug 2018
Hey guys,
i am creating a table with
eval([N '= table']);
Now i want to write data in that table with smth. like:
eval([N'.Torque1cNm = cell2mat(raw(:,1)']);
But i get the error massage
Error: This statement is incomplete.
I don´t know where my mistake is.
I hope u can help me.
Thanks in advance
  4 Commenti
Stephen23
Stephen23 il 25 Lug 2018
"I don´t know where my mistake is."
Your code is missing one closing parenthesis. Of course if you had not used awful eval then MATLAB's inbuilt code checking would have highlighted this error and made it easy to fix, but because you decided to use eval you have forced yourself into writing buggy code that is harder to debug (because none of the static code checking tools work). This is one of the reasons why the MATLAB documentation and all MATLAB experts advise against doing what you are doing:
Jan
Jan il 25 Lug 2018
@Y.J.: Please do not cross-post a question in multiple forums, because this wastes the time of the ones who post answers, when they write something, which has been posted already elsewhere. If you have a really good reason for cross-posting, please add links to the other threads in each forum. Thanks.

Accedi per commentare.

Risposte (1)

Jan
Jan il 25 Lug 2018
While the suggestions to avoid eval are the way to go, the actual problems are:
eval([N'.Torque1cNm = cell2mat(raw(:,1)']);
^ ^
The first is interpreted as transposition, and at the second mark a closing parenthesis is missing.
eval([N, '.Torque1cNm = cell2mat(raw(:,1))']);
But again: Don't do this. It is drilling a hole in your knee.

Categorie

Scopri di più su Workspace Variables and MAT-Files in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by