Setting properties of some static text boxes based on contents of another variable
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi all,
I have a GUI interface that warns a user if they try to save the data to a .MAT without filling all boxes.
handles.DataRequiredToSave = {'m','wdist','wb','h',..............};
% Check that handles structure contains all data that is required to save the item
% being created
% If it exists in the handles structure returns a 1, else returns a 0.
exists_or_not = isfield(handles,handles.DataRequiredToSave);
% Test if all returned in the previous lines are 1s
% If all exist returns 1, else returns 0.
all_exist = all(exists_or_not);
% If all data required doesn't exist, throw error message, else begin saving process.
if all_exist == 0
msgbox('Data missing - please check all fields have been filled.',
'Data Error','error');
% Highlight variables that are missing red
for datacounter = 1:length(handles.DataRequiredToSave)
if exists_or_not(1,datacounter) == 0
handlename = ['handles.text',num2str(datacounter)]
set({handlename},'ForegroundColor',[1 0 0])
end
end
else
% Save Data
There are a lot of items in DataRequiredToSave so I am trying to set the colour of the textboxes next to the edit boxes (tagged text1, text2 etc.) using a for loop, dynamically changing the handle that the set function uses in order to only set the static text for the data fields that have been accidentally left empty.
This gives me an error on the set line:
Error using set
Conversion to double from cell is not possible.
Error in Product_Data>Save_As_Menu_Callback (line
196)
set({handlename},'ForegroundColor',[1 0 0])
What am I doing wrong? Whatever I do I can't get the changing of the handle I am trying to set the properties of to work.
Thanks in advance, Matt.
댓글 수: 0
채택된 답변
Steven Lord
2016년 11월 4일
Passing a cell array containing a char vector into the set function as the first input won't work. What will work is:
handlename = handles.(['text',num2str(datacounter)])
set(handlename, 'ForegroundColor', [1 0 0])
This uses the dynamic field names feature to retrieve the appropriate field of the handles structure.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Export에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!