i need assistant making uitable

Guyz.. I need assistant about making GUI in matlab.. I wan to make 2 tables n 1 pushbutton. My prob is i cannot callback the data from the table to the pushbuttons.. These are my callback data for uitable1 n uitable2:
*table = get(hObject,'Data');
handles = guidata(hObject);
handles.table = table;
guidata(hObject, handles);**BOLD TEXT*
And then i put these coding into pushbuttons:
*handles = guidata(hObject);
table = handles.table;
table = cell2mat(table);
cost1 = get(handles.uitable1,'Data');
mwlimits1 = get(handles.uitable2,'Data');
Pdt1 = get(handles.input3_editText,'String');
guidata(hObject, handles);
cost = cell2mat(cost1);
mwlimits = cell2mat(mwlimits1);
Pdt = str2num(Pdt1);**BOLD TEXT*
Can anyone help me pls~~

 채택된 답변

slumberk
slumberk 2011년 2월 8일

0 개 추천

thx walter. I guess i have to show you the code. Do give some comments.
These are my button callback:
function add_pushbutton_Callback(hObject, eventdata, handles)
cost1 = cell2mat(get(handles.uitable1,'Data'));
mwlimits1 = cell2mat(get(handles.uitable2,'Data'));
Pdt = str2num(get(handles.input3_editText,'String'));
lambda1 = mat2cell(lambda);
set(handles.answer1_staticText,'Data', lambda1);
Pgg1 = mat2cell(Pgg);
set(handles.answer2_staticText,'Data', Pgg1);
totalcost1 = num2str(totalcost);
set(handles.answer3_staticText,'Data', totalcost1);
guidata(hObject, handles);
This are my uitable callback that you suggest:
handles.uitable1 = hObject;
guidata(hObject,handles);
These are my edit text callback:
function input1_editText_Callback(hObject, eventdata, handles)
input = str2num(get(hObject,'String'));
if (isempty(input))
set(hObject,'String','0')
end
guidata(hObject, handles);
function input1_editText_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
So basically, i have a figure with 3 input from user which includes 2 uitables and 1 edit text. And i have to push buttons and i have to generate the answer into 3 which is lambda,pgg1 and totalcost. So what do you think.. Thank you again =)

댓글 수: 4

Walter Roberson
Walter Roberson 2011년 2월 8일
* lambda is not defined at the time it is used in add_pushbutton_Callback
* There is no Data property for any uicontrol Style, or for text boxes. If you want to set the text displayed for handles.answer1_staticText then you should set the String property, and it should be set to a character array or a cell string array, not a numeric array.
* Pgg is not defined in add_pushbutton_Callback at the time it is used.
* 'String' vs 'Data' for handles.answer2_staticText and handles.answer3_staticText. Setting Data would be okay if answer1_staticText and answer2_staticText were uitable but then they would be badly misnamed.
* as you do not modify the handles structure itself any of the callbacks, you do not need to
guidata(hObject, handles);
in them.
slumberk
slumberk 2011년 2월 8일
thx again walter.. i think i have to compkete the data first. One anothere question.
I want the data table will be 3 by 3 matrix but when i make a table figure, it is automatically 4 by 2 table. When i change the row at the property inspector, i delete the 4th row but when i apply, the row does not delete. Why is this happen? How i can make it become 3 by 3 table?
Walter Roberson
Walter Roberson 2011년 2월 8일
Sorry no idea on changing the table size in Guide or through the property inspector.
slumberk
slumberk 2011년 2월 8일
owh.. ok.. thx again

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

추가 답변 (2개)

Walter Roberson
Walter Roberson 2011년 2월 8일

1 개 추천

Your callback for uitable1 should be
handles.uitable1 = hObject;
guidata(hObject,handles);
Likewise for uitable2 except setting handles.uitable2
Then your callback for the pushbutton would be like,
cost1 = cell2mat(get(handles.uitable1,'Data'));
mwlimits1 = cell2mat(get(handles.uitable2,'Data'));
Pdt = str2num(get(handles.input3_editText,'String'));
but you haven't shown any code for actually doing anything with these matrices and number once you have them, so I cannot advise past this point.
The rest of the code you show for your callbacks appears to be unnecessary if you are working in Guide -- though starting with
handles = guidata(hObject);
would be needed if you were doing your own callback programming instead of having the callbacks generated by GUIDE.
Walter Roberson
Walter Roberson 2011년 2월 8일

0 개 추천

This appears to be a continuation of your previous question, #924 and should probably have been posted as part of that.

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

질문:

2011년 2월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by