VBA-like "with" function ? + get(0,'ScreenSize')

조회 수: 2 (최근 30일)
Luis Vieira da Silva
Luis Vieira da Silva 2015년 5월 5일
댓글: Luis Vieira da Silva 2015년 5월 6일
I have just installed Matlab R2015a with the new object-oriented syntax to get/set graphic object properties e.g.:
h_quit.Enable = 'On'
instead of:
set(h_quit,'enable','on')
Very good. But is there a "with" function similar to the one in VBA, that could allow us in some cases to save characters in program ? That way, we could write:
With data.UsedByGuiData_m
.TagPanel(2).Visible = 'off'
.TagPanel(3).Visible = 'off'
.TagPanel(4).Visible = 'off'
.TagPanel(5).Visible = 'off'
endwith
instead of:
data.UsedByGuiData_m.TagPanel(2).Visible = 'off';
data.UsedByGuiData_m.TagPanel(3).Visible = 'off';
data.UsedByGuiData_m.TagPanel(4).Visible = 'off';
data.UsedByGuiData_m.TagPanel(5).Visible = 'off';
Another question related to this new syntax:
to retrieve the resolution of my computer screen, I use:
get(0,'ScreenSize')
I have tried the new syntax:
0.ScreenSize
But it doesn't work, I get the following error message:
Parse error at ScreenSize: usage might be invalid Matlab syntax.
Is it normal ?

채택된 답변

Titus Edelhofer
Titus Edelhofer 2015년 5월 5일
Hi Luis,
not really. What you can do is to assign to an intermediate variable, something like
lTagPanel = data.UsedByGuiData_m.TagPanel;
lTagPanel(2).Visible = 'off'
lTagPanel(3).Visible = 'off'
lTagPanel(4).Visible = 'off'
lTagPanel(5).Visible = 'off'
or use multiple assignments at once:
[data.UsedByGuiData_m.TagPanel(2:5).Visible] = deal('off')
although I guess easier readable would be the "set" notation in this case
set(data.UsedByGuiData_m.TagPanel(2:5), 'visible', 'off')
Regarding the question on 0: you need to create a variable
r = groot;
r.SreenSize
Since groot is a function, groot.ScreenSize does not work ...
Titus
  댓글 수: 1
Luis Vieira da Silva
Luis Vieira da Silva 2015년 5월 6일
Hi Titus,
Everything is clear. Thank you !
Luis

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by