Error with function Eval()
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Stephen23
2019-4-23
编辑:Stephen23
2019-4-23
"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
2019-4-23
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).
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!