save changes in variable pass in timer function

I want to change the value of a variable ( Precio) that i pass to a function in a timer. In the following call that variable don't update. How can update this variable. Here is the function of my timer and the arguments. Thanks
function leer_ofertas_nuevas( hObject, eventdata,Fecha, Contrato, Zona, Agente, Unidad, Precio, Cantidad, handles)

6 个评论

Please post some code, which reproduces the situation you have. Currently you show us, how the callback function is defined, but not its code.
This is the code
function leer_ofertas_nuevas( hObject, eventdata,Fecha, Contrato, Zona, Agente, Unidad, Precio, Cantidad, Tipo_oferta, Con_ejec, Con_val, Cantidad_reducida, PPD, Fecha_envio, fecha_cambiada, oferta_leida, handles)
set(handles.edit1,'String',datestr(now)); % poner la hora actualizada
% coger las ofertas que pertenencen al contrato
num_c = hour(datestr(now))+1;
hora_actual_c= datestr(duration(hours(num_c - 1),'format','hh:mm'),'HH:MM');
fecha_hoy= datetime('today','Format','yyyyMMdd');
fecha_hoy = datestr(fecha_hoy,'yyyymmdd'); %% pasar a string
for i=1:length(Contrato)
Contrato_hora{i,1}=Contrato{i,1}{1,1}(10:14);
Contrato_fecha{i,1}= Contrato{i,1}{1,1}(1:8);
end
pos_cont_hora = strcmp(Contrato_hora, hora_actual_c); % posiciones donde el contrato es igual a la hora actual
pos_cont_fecha = strcmp(Contrato_fecha, fecha_hoy); % posiciones donde el contrato es igual a la fecha actual
pos_indices = pos_cont_hora & pos_cont_fecha;
ind_cont= find(pos_indices); l
ref_tiempo = datetime('now');
for j=1:length(ind_cont)
jj = ind_cont(j);
if oferta_leida(jj) == true && datetime(fecha_cambiada{jj},'InputFormat','dd/MM/yyyy HH:mm:ss')<ref_tiempo
oferta_leida(jj)= null; % fue ingresada en la ultima iteración
elseif oferta_leida(jj) == false && datetime(fecha_cambiada{jj},'InputFormat','dd/MM/yyyy HH:mm:ss')<ref_tiempo
oferta_leida(jj)= true; % se inserta por primera vez
end
end
oferta_leida_this_hour=oferta_leida(ind_cont); % ofertas que pertenecen a los contratos de la hora en cuestion
ind_true=find(oferta_leida_this_hour); % dentro de los anteriores ofertas los que cumplen la condición
ind_cond= ind_cont(ind_true); % indices de las anteriores ofertas
%%%insertar datos
for k = 1:length(ind_cond)
kk = ind_cond(k);
S.Fecha = Fecha{kk};
S.Contrato = Contrato{kk}{1};
S.Zona = Zona{kk};
S.Agente = Agente{kk};
S.Unidad = Unidad{kk};
S.Precio = Precio{kk};
S.Cantidad = Cantidad{kk};
S.Tipo_oferta = Tipo_oferta{kk};
S.Condicion_ejecucion = Con_ejec{kk};
S.Condicion_validez = Con_val{kk};
S.Cantidad_reducida = Cantidad_reducida{kk};
S.PPD = PPD{kk};
S.Fecha_envio = Fecha_envio{kk};
S.Fecha_cambiada = fecha_cambiada{kk};
ofertas_c(k) = S;
end
ofertas_cell_c={ofertas_c.Fecha; ofertas_c.Contrato; ofertas_c.Zona; ofertas_c.Agente; ofertas_c.Unidad; ofertas_c.Precio; ofertas_c.Cantidad; ofertas_c.Tipo_oferta; ofertas_c.Condicion_ejecucion; ofertas_c.Condicion_validez; ofertas_c.Cantidad_reducida; ofertas_c.PPD; ofertas_c.Fecha_envio; ofertas_c.Fecha_cambiada}';
% Asignar datos a la tabla
set(handles.uitable1,'Data',ofertas_cell_c);
What do you think is a suitable option for this code?
When Precios is changed in the code, have your code store a copy of it in the UserData property of the timer object, and do not pass it in. Have the function pull the value out of the UserData of hObject.

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Programmatic Model Editing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by