is there a way to make it to where if a checkbox is checked then that corresponding word will show up in the text area?

6 次查看(过去 30 天)
i am using app designer and i am trying to get it to where if a check box is checked then it will display the name in the text area. this below is what in have for when a button is pushed fpmc fpcoy and fprg are set as words in the properties. and i want it to show up if the box for those is checked shown in the picture
and i want it to display like this
Flatpack mc
Flatpack Coy
Flatpack Rg
not Flatpack mc Flatpack Coy Flatpack Rg
i can get it to work but only for the Rg one
thank you
function DoneButton_4Pushed(app, event)
po=num2cell(app.PoEditField.Value);
fp1=app.FlatpackMcCheckBox.Value;
fp2=app.FlatpackCoyCheckBox.Value;
fp3=app.FlatpackRGCheckBox.Value;
if fp1==1
fpp=[app.fpmc];
else
fpp=0; % want to leave it blank;
end
if fp2==1
fpp=[app.fpcoy];
else
fpp=0;
end
if fp3==1
fpp=[app.fprg];
else
fpp=0;
end
app.PoTextArea.Value=[string(po)];
app.ProductTextArea.Value=[string(fpp)];

采纳的回答

Aghamarsh Varanasi
Aghamarsh Varanasi 2021-6-18
编辑:Aghamarsh Varanasi 2021-6-18
Hi,
You can use string array to achieve this functionality. For reference, you can use the following code snippet
function DoneButton_4Pushed(app, event)
fpp = strings(1,3);
c = 0;
% if the 'app.FlatpackMcCheckBox.Value' is false, fpp(1) is left empty
if app.FlatpackMcCheckBox.Value
fpp(c+1) = app.fpmc;
c = c + 1;
end
if app.FlatpackCoyCheckBox.Value
fpp(c+1) = app.fpcoy;
c = c + 1;
end
if app.FlatpackRGCheckBox.Value
fpp(c+1) = app.fprg;
c = c + 1;
end
app.ProductTextArea.Value= fpp ;
end
Hope this helps
  9 个评论
Joseph Catanese
Joseph Catanese 2021-6-18
编辑:Joseph Catanese 2021-6-18
so num2str?
with the numbers i have it as a variable entered rather then just numbers.
the numbers are matrixs too and i tried using mat2str but i dont know
fpmct =[fpqt1/ttfp1,fpqt1/ttfp2,fpqt1/ttfp3]'
time=strings(1,6)
t=0;
t(t+1)=string(mat2str(fpcoyt/60,2));
app.TimeTextArea.Value=time;
error msg
Unable to perform assignment because the left and right sides have a different number of elements.
Walter Roberson
Walter Roberson 2021-6-18
t=0;
That creates t as a scalar numeric value
t(t+1)=string(mat2str(fpcoyt/60,2));
t has scalar numeric value 0, so t(t+1) is t(1) and identifies a scalar numeric output location.
The right hand side, on the other hand, is a string object or string array. mat2str() returns a character vector n matter what the shape of the input is, so string() of that would be a string scalar. Then because the result is being assigned into a numeric scalar, the string() class will attempt to convert the string scalar to numeric.
Now, if you use mat2str() with a scalar numeric value, then the result will be the scalar numeric value as a character vector, without any "decoration". For example, mat2str(5) is going to give you '5', not '[5]' . And it so happens that if you assign a string scalar has has the form of a scalar number, in a context that needs a double, then the string() class will do the equivalent of str2double() [except faster!!] . The numeric value that would end in in t(1) would, in that case, be the same scalar numeric value as was input, except possibly rounded.
If you use mat2str() with something that is not a scalar numeric value, then the result will have decorations, such as mat2str(4:5) giving the result '[4 5]' . And when the string() class tries to convert that to double to store into t(1) then the result you would get in t(1) would be NaN.
Meanwhile, you created the variable time as a 1 x 6 string array, each empty strings, and that string array is what you assign to the Value, even though you did not store anything into it. But you ignore the numeric value that you stored into t(1) after you put it there.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by