Error with function Eval()

7 views (last 30 days)
Pedro Guevara
Pedro Guevara on 23 Apr 2019
Commented: Guillaume on 23 Apr 2019
Goodnight. The reason for my message was to ask them again for help with a problem I'm having with the eval function. When I run the program step by step and it goes through the 175 matlab code line it throws me the following error:
Indices: row and column indices of the cell (s) edited
PreviousData: previous data for the cell (s) edited
EditData: string (s) entered by the user
NewData: EditData or its converted form on the Data property. Empty if Data was not changed
Error: string error when failed to convert EditData to appropriate value for Data
handles structure with handles and user data (see GUIDATA)
Could someone help me solve it? since it is the first time that I have problems with the use of the Eval function in my program, and I do not know what can be done. Thank.
  5 Comments
Stephen23
Stephen23 on 23 Apr 2019
Edited: Stephen23 on 23 Apr 2019
"mi uso de la función Eval () se debe a que necesito generar un número N de matrices para el programa que estoy haciendo, y no conozco otra forma de hacerlo que usar esa función"
You do NOT need to use slow, complex, buggy eval just to create multiple arrays.
Just use indexing with a cell array. Indexing is simple, neat, and very efficient (unlike what you are trying to do). Read the link I gave you earlier, and these:
Guillaume
Guillaume on 23 Apr 2019
I need to generate N number of matrices for the program I'm doing, and I do not know any other way to do it than using that function.
It's simple: if you start numbering variables or start naming them in any form of sequence, you're doing it wrong.
Clearly, all these variables are related so their content should be stored together in a single container. It could be a multidimensional matrix (if all the variables are the same size) or a cell array (if not), or a structure, or a map. In your case, a cell array is probably the solution so instead of :
eval(['Posi_en_Celda', int2str( celdas ) ,' = CelDig']);
you'd have:
Posi_en_Celda{celdas} = CelDig;
No need for eval. Simpler code. Faster. Easier to debug (matlab can't check syntax inside an eval).
Another thing that is considered by most just as evil as eval is global. Again, there are much better ways to pass data to callbacks (e.g. the handle structure that you already have).

Sign in to comment.

Answers (0)

Categories

Find more on Variables in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!