MATLAB Answers

0

Error with function Eval()

Pedro Guevara さんによって質問されました 2019 年 4 月 23 日
最新アクティビティ Guillaume
さんによって コメントされました 2019 年 4 月 23 日
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 件のコメント

Pedro Guevara 2019 年 4 月 23 日
Good morning Thanks for your quick response. Checking my code lines I do not see that they lack anything like a typing error, in fact the program stops specifically on that line. If it is easier for you I could leave several lines of code to help me understand the problem. On the other hand, my use of the Eval () function is because 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. Thank you very much for your help.
function TablaDatosElementos_CellEditCallback(hObject, eventdata, handles)
% hObject handle to TablaDatosElementos (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.TABLE)
% 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 set on the Data property. Empty if Data was not changed
% Error: error string when failed to convert EditData to appropriate value for Data
% handles structure with handles and user data (see GUIDATA)
global celdas
celdas=celdas+1;
global V_org
Aux_guar=[];
CelDig = []; % Crea un vector vacio que llevara la informacion de cual fue la ultima celda digitada.
CelDig = eventdata.Indices;% Recibe la informacion de cual fue la ultima celda digitada (posicion donde fue digitada).
Celda_dig_Mis_Ele= [];
Coor_nodos1= [];
Aux_guar=[];
VarElem_F=str2double(get(handles.NumElem,'string'));
datos=get(handles.TablaDatosElementos,'Data');
datos=str2double([datos(1:VarElem_F,1:7)]);
Guardar_pos_celda_dig1 =['Posi_en_Celda', int2str( celdas ) ,' = CelDig'];%
eval(Guardar_pos_celda_dig1) % Pone en la "ventana de comando" la posicion del dato digitado. EJE: Posi_en_Celda1 = 2 6
V_org(celdas,1)=eval(['Posi_en_Celda', num2str(celdas),'(1,1)']); % guarda posicion "fila" de la celda digitada en la matriz V_org.
V_org(celdas,2)=eval(['Posi_en_Celda', num2str(celdas),'(1,2)']); % guarda posicion "columna" de la celda digitada en la matriz V_org.
V_org(celdas,3)=celdas; % guarda el orden en que fue digitada de la celda con el dato en la matriz V_org.
BB1=find(V_org(:,1)== V_org(celdas,1) );
%V_org=sortrows(V_org,1);
%disp(V_org)
BB2=[ BB1 , V_org(BB1,3) ]; % [ 2 primeras columnas de indican la posicion donde fue introduccido , la tercera indica en que momento fue introduccioda ]
disp(BB2)
%////////////////////////////////////////////////////////////////////////
%Guarda_pos_igual
j=1;
f=1;
for f = 1:celdas
Pos_iguales=find( V_org( 1:celdas, 1 ) == V_org(celdas,1) );
Pos_iguales=Pos_iguales';
if length(Pos_iguales)>1 %Si hay mas de 1 celdas digitada que tiene el mismo indice de fila (los datos estan en la misma fila) entra
Celda_dig_Mis_Ele =['Posi_en_Celda_mismo ', V_org(celdas,1) ,' = Pos_iguales'];%
eval(Celda_dig_Mis_Ele)
eval(['Posi_en_Celda_mismo ', num2str( V_org(celdas,1) ) ] );% Pone en la "ventana de comando" las posiciones de mismo elemento.
else
pedro1=2;
disp(pedro1)
%V_org(celdas,1)
end
end
Stephen Cobeldick
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).

サインイン to comment.

製品

0 件の回答


Translated by