Variable / which matlab does not forget ?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Max Müller
el 29 de Jul. de 2014
Comentada: Joseph Cheng
el 29 de Jul. de 2014
Hey Guys,
function testbutton_Callback(hObject, eventdata, handles)
x = get(handles.edit1,'String')
if ~exist('x','var')
x = []
end
y = [y,x]
This code is supposed to read the edit box and create an array which contains the Data. The array is supposed to expand every time u click the button. However, if the procedure is finished, matlab forgets/kills the x-value. now i want to know, how can i make matlab remember the X-Value after the procedure is done?
0 comentarios
Respuesta aceptada
Joseph Cheng
el 29 de Jul. de 2014
You could use the userdata and store the values within the edit 1 box data field
userdata = get(handles.edit1,'userdata');
edit1stuff = get(handles.edit1,'String');
set(handles.edit1,'userdata',[userdata;edit1stuff])
since at the starts unless otherwise declared the userdata is empty for the field.
1 comentario
Joseph Cheng
el 29 de Jul. de 2014
doing a very quick search i was able to find this link that shows the difference between the get and getappdata and the set and setappdata
from skimming the post the difference is between meaningful to you and meaningful to matlab. in my example i use userdata but if you use the setappdata you can put anything you want without having to muddy the waters with the extra matlab declared stuff.
Más respuestas (2)
Azzi Abdelmalek
el 29 de Jul. de 2014
Nothing is forgotten, you can the value of x at any time
x = get(handles.edit1,'String')
1 comentario
Julia
el 29 de Jul. de 2014
Hi,
try this:
Declare an array/variable y in the opening function
handles.y=0;
and update y every time you write a new value in it:
y=[y,x];
guidata(hObject, handles); % updates handles structure
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!