mHelpMe
mHelpMe

Reputation: 6668

getting the value from a checkbox in Matlab 2018

I am upgrading my Matlab from 2013b to 2018b and have found out that MathWorks have made quite a few changes to the GUI's.

One problem I am having is getting the value of checkbox. The line below is the code I used to use but now it doesn't work.

if get(handles.check_perf_attr,'Value') == 1

The error message is,

Undefined operator '==' for input arguments of type 'cell'.

So I tried the line below to just get the value that is being returned and then apply some logic.

tValue = get(handles.check_perf_attr,'Value');

However tValue is 2 x 1 cell which in (1, 1) = 0 & (2, 1) = 1. I don't really understand this as surely a checkbox can only be one value true (1) or false (0)?

Upvotes: 0

Views: 528

Answers (2)

L. Scott Johnson
L. Scott Johnson

Reputation: 4382

"Dot notation is a new syntax to access object properties starting in R2014b."

so try

if handles.check_perf_attr.Value == 1

or

tValue = handles.check_perf_attr.Value;

Upvotes: 1

Cris Luengo
Cris Luengo

Reputation: 60494

get returns a cell array with values when applied to an array of handles.

Thus, I think your problem is that handles.check_perf_attr contains two handles, not one.

Upvotes: 1

Related Questions