GUI uitable logical values
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
SO I HAVE this ui table i want to select sujects and push 'submit' to calculate the sum of credit for the subject i selected
i dont know how to dealing with uitable to get data from it and calculat the sum
and after that i want to push a clear' button to reset all
help please

채택된 답변
0 개 추천
"SO I HAVE this ui table i want to select sujects and push 'submit' to calculate the sum of credit for the subject i selected"
In the callback function for the "submit" button, add this section of cose. You'll need to adapt it to your gui. That means you'll need to change the variable names and the column numbers.
% I create a fake UI table just for the example
h.uitable = uitable('Data', [{false;true;true;false;false},num2cell((1:5)')], 'ColumnEdit', [true, true],'ColumnName', {'Select','Credit'});
% In my table, the check boxes are in column 1, then credits are in column 2.
% * you'll need to adapt this to your table (the variable names and column numbers)
% * These steps could be combined into 1 line but it's more intuitive this way
% Step 1) Determine which rows have checked boxes
rowChecked = [h.uitable.Data{:,1}]';
% Step 2) Get the credits for each row of checked boxes
credits = [h.uitable.Data{rowChecked,2}]';
% Step 3) add the credits
creditSum = sum(credits);
"and after that i want to push a clear' button to reset all"
In the callback function to you "clear" button, add this section of code. Again, you'll need to adapt it to your GUI.
% set all checkboxes to false
h.uitable.Data(:,1) = {false};
% Remove all credits
h.uitable.Data(:,2) = [];
댓글 수: 18
geeks g
2019년 5월 17일
sorry, Actually i didnt understand you well.
can you help me more.
Adam Danz
2019년 5월 17일
Do you have specific questions?
@Adam Danz
i use for exaple
set or get like
set(handles.uitable,'data',false );
this stetment , make me clear all chekboxes????
Close, but not correct.
The set() version would be
data = get(h.uitable,'Data');
data(:,1) = {false};
set(h.uitable,'Data',data)
But if you can use the dot notation rather than get(), set(), you should.
geeks g
2019년 5월 17일
Adam Danz
2019년 5월 17일
No problem, let me know if you have further questions about this.
geeks g
2019년 5월 17일
I WRITE LIKE YOU TELL ME
NOTHING WORK
AND THERE IS AN ERROE
this my code: after i adapt it to my GUI.
% Step 1) Determine which rows have checked boxes
rowChecked = [handles.uitable.Data{:,1}];
rowChecke = [handles.uitable.Data{:,4}];
% Step 2) Get the credits for each row of checked boxes
credits = [handles.uitable.Data{rowChecked,2}];
credit = [handles.uitable.Data{rowChecke,6}];
% Step 3) add the credits
creditSum = sum(credits);
creditSu = sum(credit);
a = creditSum +creditSu ;
What's the complete copy-pasted error message?
geeks g
2019년 5월 17일
i put this code in 'submit' button
then i run the program
its ok until now
when i push 'submit'
this error show up
------------------------------
>> Course_Selector_
Reference to non-existent field 'uitable'.
Error in Course_Selector_>pushbutton4_Callback (line 340)
rowChecked = [handles.uitable.Data{:,1}];
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Course_Selector_ (line 63)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Course_Selector_('pushbutton4_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
>>
The error message tells you what's wrong:
Reference to non-existent field 'uitable'.
There is no field in "handles" named 'uitable'.
1) Are you writing this in GUIDE or app designer (or something else)?
2) Is this code in the callback function to the submit button?
Please copy-paste the entire call-back function here and please format the code using the format button.
geeks g
2019년 5월 17일
omg omg omg
its work its work
omg it work
but know how could i mov the result of sum AND put it in text?
Ha! Glad to hear it's working! :)
To display the result in your GUI, you need to convert it to a string and assign it to a text object. Let's say your text box is named "textfield".
handles.textfield.String = num2str(creditSum);
% or, to specify number of decimal places
handles.textfield.String = sprintf('%.1f',creditSum);
look to this code please
is that ok??
% Step 1) Determine which rows have checked boxes
rowChecked = [handles.uitable1.Data{:,1}];
rowChecke = [handles.uitable1.Data{:,4}];
% Step 2) Get the credits for each row of checked boxes
credits = [handles.uitable1.Data{rowChecked,2}];
credit = [handles.uitable1.Data{rowChecke,6}];
% Step 3) add the credits
creditSum = sum(credits);
creditSu = sum(credit);
a = creditSum + creditSu ;
set(handles.text7,'string',a);
Adam Danz
2019년 5월 18일
Does it work?
In my examples, I convert 'a' from number to string using one of the two methods below
- num2str(a);
- sprintf('%.1f',a);
geeks g
2019년 5월 18일
how could i use 'enable' in ui table
if i choose a specialty (IT) in university
i want some subjects to be non enable
Adam Danz
2019년 5월 18일
Read about the 'enable' property here:
When 'enable' is turned off, the entire table is deactivated. You can't apply this to certain cells. Instead, you could change the selection available whenever a new specialtiy is chosen. For example, whenever IT is chosen the table content could change to a new list.
geeks g
2019년 5월 18일
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
