필터 지우기
필터 지우기

Variable / which matlab does not forget ?

조회 수: 2 (최근 30일)
Max Müller
Max Müller 2014년 7월 29일
댓글: Joseph Cheng 2014년 7월 29일
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?

채택된 답변

Joseph Cheng
Joseph Cheng 2014년 7월 29일
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
Joseph Cheng
Joseph Cheng 2014년 7월 29일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 7월 29일
Nothing is forgotten, you can the value of x at any time
x = get(handles.edit1,'String')
  댓글 수: 1
Max Müller
Max Müller 2014년 7월 29일
편집: Max Müller 2014년 7월 29일
function AddAnotherShotButton_Callback(hObject, eventdata, handles)
shotnumber = str2num(get(handles.ShotEditbox,'String'));
UsedAmp = get(handles.UsedAmpRadioButton,'Value');
ClosestAmp = get(handles.ClosestAmpRadioButton,'Value');
OptimalAmp = get(handles.OptimalAmpRadioButton,'Value');
if ~exist('InputData','var')
InputData = [];
end
InputDataAppend = [shotnumber;UsedAmp;ClosestAmp;OptimalAmp]
InputData = [InputData,InputDataAppend]
set(handles.ShotEditbox,'String','');
set(handles.UsedAmpRadioButton,'Value',0);
set(handles.ClosestAmpRadioButton,'Value',0);
set(handles.OptimalAmpRadioButton,'Value',0);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I want to:
get all the InputData
store it in an array
clear all InputObjects
get next InputData
store it .....

댓글을 달려면 로그인하십시오.


Julia
Julia 2014년 7월 29일
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
  댓글 수: 1
Max Müller
Max Müller 2014년 7월 29일
Thats one way i guess....my mentor told me to use getappdata/setappdata. The syntax is setappdata(h,name,val), but i miss an example.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by