How can I use a checkbox value to determine whether to clear other elements in App Designer?

3 次查看(过去 30 天)
I am trying to make the app clear values from edit fields if their corresponding checkbox is unchecked.
When I try to run the code below, I don't get any errors, but nothing happens either.
p = checkbox
ef = text edit field
r,b,f = numeric edit fields
function ClearButtonPushed(app, event)
p=[app.p1.Value,app.p2.Value,app.p3.Value,app.p4.Value,app.p5.Value,app.p6.Value,...
app.p7.Value,app.p8.Value,app.p9.Value,app.p10.Value,app.p11.Value,app.p12.Value];
ef=[app.ef1.Value,app.ef2.Value,app.ef3.Value,app.ef4.Value,app.ef5.Value,app.ef6.Value,...
app.ef7.Value,app.ef8.Value,app.ef9.Value,app.ef10.Value,app.ef11.Value,app.ef12.Value];
r=[app.r1.Value,app.r2.Value,app.r3.Value,app.r4.Value,app.r5.Value,app.r6.Value,...
app.r7.Value,app.r8.Value,app.r9.Value,app.p10.Value,app.p11.Value,app.p12.Value];
b=[app.b1.Value,app.b2.Value,app.b3.Value,app.b4.Value,app.b5.Value,app.b6.Value,...
app.b7.Value,app.b8.Value,app.b9.Value,app.b10.Value,app.b11.Value,app.b12.Value];
f=[app.f1.Value,app.f2.Value,app.f3.Value,app.f4.Value,app.f5.Value,app.f6.Value,...
app.f7.Value,app.f8.Value,app.f9.Value,app.f10.Value,app.f11.Value,app.f12.Value];
for n=1:12
if(p(n) == 0)
ef(n) = ' ';
r(n) = 0;
b(n) = 0;
f(n) = 0;
end
end
end

采纳的回答

Geoff Hayes
Geoff Hayes 2019-2-19
Jacob - your arrays like
ef=[app.ef1.Value,app.ef2.Value,app.ef3.Value,app.ef4.Value,app.ef5.Value,app.ef6.Value,...
app.ef7.Value,app.ef8.Value,app.ef9.Value,app.ef10.Value,app.ef11.Value,app.ef12.Value];
are just values and not handles to the objects that you want clear/reset. You might want to try storing the handles in each array like
ef=[app.ef1, app.ef2, app.ef3, app.ef4, app.ef5, app.ef6, ...
app.ef7, app.ef8, app.ef9, app.ef10, app.ef11, app.ef12];
and then access these handles as
for n=1:12
if(p(n).Value == 0)
ef(n).Value = '';
r(n).Value = 0;
b(n).Value = 0;
f(n).Value = 0;
end
end
I don't know if the above will work...and I suspect that there are alternatives to this...but give it a try.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by