MATLAB Answers

0

How can I duplicate the data entered in a table instantaneously?

Pedro Guevara さんによって質問されました 2019 年 5 月 26 日
最新アクティビティ Pedro Guevara さんによって コメントされました 2019 年 5 月 26 日
Goodnight. I have the following problem I have a table that has the columns "Initial node" (col 4) and "Final node" (col 5) and columns 6-7 for the Cartesian components XY of the initial node and columns 8-9 for the Cartesian components XY of the final node. What I want is the following. If there is a node (either the initial or the end) that has its corresponding XY components and then the user digicates that same node in some of the initial or final columns (columns 4 or 5) I want that same node to take the coordinates of the node previously fingered Example:
Tabla.JPG
---> my uitable is called "TablaDatosElementos"
---> The schedule for the table must be within the event "CellEditCallbackCellEditCallback,"
-> Note: It is important to mention that my uitable "TableDataElements" is of variable size in terms of rows.
Thank you very much and I hope you can help me since I have been with this problem for several days and I have not been able to solve it with anything.

  4 件のコメント

Pedro Guevara 2019 年 5 月 26 日
I have a code, but [it's quite long. Everything seems to indicate that it works well but I can not get the data to go to the correct one. Then you leave them trying to explain some lines of code:
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
global pri_entrada
global V_org
global Tab_nodos
global datos
Aux_guar=[];
CelDig = []; %Create an empty vector that carries the information of which was the last cell typed.
CelDig = eventdata.Indices; % Receive the information of which was the last cell typed (position where it was typed).
Coor_nodos1= [];
Aux_guar=[];
VarElem_F=str2double(get(handles.NumElem,'string')); @define how many rows my table will have
datos=get(handles.TablaDatosElementos,'Data'); @define how many rows my table will have
datos=str2double([datos(1:VarElem_F,1:10)]);
if ( CelDig(1,2)== 4 || CelDig(1,2)== 5 ) @The variable "cells" was created with the purpose of knowing in what instant each cell of columns 4 or 5 was typed (The first cell, the second, the third, the fourth ... etc)
celdas=celdas+1;
else
disp('No intro Nodo')
end
Guardar_pos_celda_dig1 =['Posi_en_Celda', int2str( celdas ) ,' = CelDig'];%
eval(Guardar_pos_celda_dig1) % Puts in the "command window" the position of the digitized data. AXIS: Posi_en_Celda1 = 2 6
V_org(celdas,1)=eval(['Posi_en_Celda', num2str(celdas),'(1,1)']); % saves the "row" position of the cell entered in the matrix V_org.
V_org(celdas,2)=eval(['Posi_en_Celda', num2str(celdas),'(1,2)']); % saves the "column" position of the cell entered in the matrix V_org.
V_org(celdas,3)=celdas; % saves the order in which it was entered from the cell with the data in the matrix V_org.
V_org(celdas,4)= datos ( CelDig(1,1) , CelDig(1,2) ) ; % The data of the last digit cell.
BB1=find(V_org(:,1)== V_org(celdas,1) );
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)
%////////////////////////////////////////////////////////////////////////
Pos_igual=find( V_org( 1:celdas, 1 ) == V_org(celdas,1) );
if length(Pos_igual)>1 % If there are more than 1 cells typed that have the same row index (the data is in the same row) enter
Celda_dig_Mis_Ele =['Posi',int2str(V_org(celdas,1)),' = Pos_igual'];
eval(Celda_dig_Mis_Ele)
eval(['Posi', num2str( V_org(celdas,1) ) ] ); % Places the same item positions in the "command window".
vec_pos=eval ( ['Posi', int2str( V_org(celdas,1 ) ) ] );
if length(vec_pos)==2 && ~isnan(datos (V_org(celdas,1),6) )==1 && ~isnan(datos (V_org(celdas,1),7) )==1 && ~isnan(datos (V_org(celdas,1),8) )==1 && ~isnan(datos (V_org(celdas,1),9) )==1 % 2 nodes entered in the same element at different times
Tab_nodos ( V_org( celdas,1 ) , 1 ) = V_org( celdas,1 );
Tab_nodos ( V_org( celdas,1 ) , 2 ) = datos( V_org(celdas,1) , 4 );
Tab_nodos ( V_org( celdas,1 ) , 3 ) = datos( V_org(celdas,1) , 5 );
Tab_nodos ( V_org( celdas,1 ) , 4 ) = datos( V_org(celdas,1) , 6 );
Tab_nodos ( V_org( celdas,1 ) , 5 ) = datos( V_org(celdas,1) , 7 );
Tab_nodos ( V_org( celdas,1 ) , 6 ) = datos( V_org(celdas,1) , 8 );
Tab_nodos ( V_org( celdas,1 ) , 7 ) = datos( V_org(celdas,1) , 9 );
Var_Long = ( ( datos( V_org(celdas,1) , 6 ) - datos( V_org(celdas,1) , 8 ) )^2 + ( datos( V_org(celdas,1) , 7 ) - datos( V_org(celdas,1) , 9 ) )^2 )^0.5; ;
Var_Ang = 180 * (atan ( ( datos( V_org(celdas,1) , 7 ) - datos( V_org(celdas,1) , 9 ) ) / (datos( V_org(celdas,1) , 6 )-datos( V_org(celdas,1) , 8 ) ) ))/3.14159265359 ;
Tab_nodos ( V_org( celdas,1 ) , 8 ) = Var_Long;
Tab_nodos ( V_org( celdas,1 ) , 9 ) = Var_Ang;
end
else
disp('No hay coincidencias')
end
%////////////////////////////////////////////////////////////////////////
[Pos_igual1x,Pos_igual1y] = find( V_org ( 1:celdas-1 , 4 ) == V_org(celdas,4) );
% Find 2 equal nodes in columns 4 and / or 5 and save their positions
if isempty (Pos_igual1x)
Pos_igual1x = NaN(1,1);
end
[repx,repy] = find ( datos ( 1:VarElem_F ,4:5 ) == datos ( CelDig (1,1) , CelDig (1,2) ) );
j=1;
for j = 1:length (Pos_igual1x) % for
if ( length(repx)>1 && ~isnan( datos( V_org (Pos_igual1x(j,1) , 1 ), 6 ) )==1 && ~isnan( datos( V_org (Pos_igual1x(j,1) , 1 ), 7 ) )==1 && ~isnan( datos( V_org (Pos_igual1x(j,1) , 1 ), 8 ) )==1 && ~isnan( datos( V_org (Pos_igual1x(j,1) , 1 ), 9 ) )==1 )
if ~isnan( datos( V_org (Pos_igual1x(j,1) , 1 ), 6 ) )==1 && ~isnan( datos( V_org (Pos_igual1x(j,1) , 1 ), 7 ) )==1 % goes to evaluate if the columns of NIx and NIy have values
if ( V_org (Pos_igual1x (j,1) , 2 ) == V_org ( celdas, 2 ) && V_org (Pos_igual1x (j,1) , 2 ) == 4 ) % Compare if the position of any previous cell (left part) is equal to the position of the last digit cell
TablaDatosElementos.Data(V_org(celdas,1),6) = datos ( V_org (Pos_igual1x (j,1) , 1 ) , 6) ; % ACA IS WHERE I AM HAVING THE PROBLEM, I DO NOT GET THE DATA TO BE TRANSFERRED TO THE UITABLE "TablaDatosElementos"
TablaDatosElementos.Data(V_org(celdas,1),7) = datos ( V_org (Pos_igual1x (j,1) , 1 ) , 7) ; % ACA IS WHERE I AM HAVING THE PROBLEM, I DO NOT GET THE DATA TO BE TRANSFERRED TO THE UITABLE "TablaDatosElementos"
elseif ( V_org (Pos_igual1x (j,1) , 2 ) ~= V_org ( celdas, 2 ) && V_org (Pos_igual1x (j,1) , 2 ) == 4 )
TablaDatosElementos.Data( V_org(celdas,1), 8) = datos ( V_org (Pos_igual1x (j,1) , 1 ) , 6 ) ; % Here WHERE I AM HAVING THE PROBLEM, I DO NOT GET THE DATA TO BE TRANSFERRED TO THE UITABLE "TablaDatosElementos"
TablaDatosElementos.Data( V_org(celdas,1), 9) = datos ( V_org (Pos_igual1x (j,1) , 1 ) , 7 ) ; % Here WHERE I AM HAVING THE PROBLEM, I DO NOT GET THE DATA TO BE TRANSFERRED TO THE UITABLE "TablaDatosElementos"
end
end
if ~isnan( datos( V_org (Pos_igual1x(j,1) , 1 ), 8 ) )==1 && ~isnan( datos( V_org (Pos_igual1x(j,1) , 1 ), 9 ) )==1
% goes to evaluate if the columns of NFx and NFy have values
if ( V_org (Pos_igual1x (j,1) , 2 ) == V_org ( celdas, 2 ) && V_org (Pos_igual1x (j,1) , 2 ) == 5 ) % Compare if the position of any previous cell (left part) is equal to the position of the last digit cell
TablaDatosElementos.Data(V_org(celdas,1),8) = datos ( V_org (Pos_igual1x (j,1) , 1 ) , 8) ;
TablaDatosElementos.Data(V_org(celdas,1),9) = datos ( V_org (Pos_igual1x (j,1) , 1 ) , 9) ;
elseif ( V_org (Pos_igual1x (j,1) , 2 ) == V_org ( celdas, 2 ) && V_org (Pos_igual1x (j,1) , 2 ) == 4 )
TablaDatosElementos.Data( V_org(celdas,1), 6) = datos ( V_org (Pos_igual1x (j,1) , 1 ) , 8 ) ;
TablaDatosElementos.Data( V_org(celdas,1), 7) = datos ( V_org (Pos_igual1x (j,1) , 1 ) , 9 ) ;
end
end
else
end
end
dpb
2019 年 5 月 26 日
"Everything seems to indicate that it works well but I can not get the data to go to the correct one."
What does that mean, specifically? Isolating the specific portion with which you're having trouble would probably help with some context...
Pedro Guevara 2019 年 5 月 26 日
It is this part. I do not get that " datos (V_org (Pos_igual1x (j, 1), 1), 6); " sent the data to the uitable.
if (V_org (Pos_igual1x (j, 1), 2) == V_org (celdas, 2) && V_org (Pos_igual1x (j, 1), 2) == 4) % Comparar si la posición de cualquier celda anterior (parte izquierda) es igual a la posición de la celda del último dígito
TablaDatosElementos.Data (V_org (celdas, 1), 6) = datos (V_org (Pos_igual1x (j, 1), 1), 6); % THIS LINE IS WHERE I HAVE THE PROBLEM
TablaDatosElementos.Data (V_org (celdas, 1), 7) = datos (V_org (Pos_igual1x (j, 1), 1), 7); % THIS LINE IS WHERE I HAVE THE PROBLEM
elseif (V_org (Pos_igual1x (j, 1), 2) ~ = V_org (celdas, 2) && V_org (Pos_igual1x (j, 1), 2) == 4)
TablaDatosElementos.Data (V_org (celdas, 1), 8) = datos (V_org (Pos_igual1x (j, 1), 1), 6); % THIS LINE IS WHERE I HAVE THE PROBLEM
TablaDatosElementos.Data (V_org (celdas, 1), 9) = datos (V_org (Pos_igual1x (j, 1), 1), 7); % THIS LINE IS WHERE I HAVE THE PROBLEM
end

サインイン to comment.

0 件の回答


Translated by