Filter löschen
Filter löschen

How to access table with eval?

6 Ansichten (letzte 30 Tage)
Y. J.
Y. J. am 25 Jul. 2018
Beantwortet: Jan am 25 Jul. 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 Kommentare
Stephen23
Stephen23 am 25 Jul. 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 am 25 Jul. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 25 Jul. 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.

Kategorien

Mehr zu Workspace Variables and MAT-Files finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by