How to set BackgroundColor on edit text using mycode and fix 1 error?

2 ビュー (過去 30 日間)
acosep
acosep 2015 年 9 月 18 日
回答済み: Walter Roberson 2015 年 9 月 18 日
function [] = main ()
figure('name','CROSSWORD PUZZLE','MenuBar','none','Color',[.7,.78,1],'units','normalized','outerposition',[0 0 .5 .8]')
Title='CROSSWORD';
a=1;
for x=20:30:260
tagn=strcat('TBox',num2str(a));
uicontrol('Style','edit','position',[x, 530, 30, 30],'String',Title(a),'FontSize',20,'Tag',tagn)
a=a+1;
end
TitleB='PUZZLE';
a=1;
for x=80:30:230
tagn=strcat('TBox1',num2str(a));
uicontrol('Style','edit','position',[x, 500, 30, 30],'String',TitleB(a),'FontSize',20,'Tag',tagn)
a=a+1;
end
S.pb = uicontrol('Style','pushbutton','Position',[500 350 60 30],'String','PLAY');
set(S.pb,'callback',@game)
S.ob = uicontrol('Style','pushbutton','Position',[500 300 60 30],'String','OPTION');
set(S.ob,'callback',@set)
function [] = game(hObject, eventdata, handles)
set(hObject,'Visible','off');
[numeric,strings]=xlsread('puz.xlsx', 'sheet1', 'A1:N14');
a=1;
for x=20:30:620
for y=420:-30:30
Ebox(a)=uicontrol('Style','edit','position',[x y 30 30],'FontSize',20,'String',strings(a))
if string(a)==''
set(Ebox(a),'BackgroundColor','black')
end
a=a+1;
end
end

採用された回答

Walter Roberson
Walter Roberson 2015 年 9 月 18 日
You do not define "string". You do define "strings", but that output from xlsread() would be a cell array of strings so you would need {} indexing to access it:
if isempty(strings(a)) %(if you are checking for empty entry)
or
if strcmp(strings(a), ' ') %(if you are checking for blank)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWord games についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by