Why does get(handles.editbox, 'String') return a char when the box is empty but a cell for all other cases?

1 view (last 30 days)
Is this expected behavior or is it a bug?
I finally tracked down a frustrating bug to this behavior, as I was tacking the contents of several edit boxes onto the end of a cell array.
I worked around by writing my own getEditboxContents function that always returns a cell, but that seems like it shouldn't be necessary.
What is the best practice for handling this case?
Cheers

Accepted Answer

Geoff Hayes
Geoff Hayes on 10 Oct 2014
Nicholas - I suspect that this is expected behaviour. If the edit box control allows for multiple lines (because the Max property is greater than the Min property), then the return of
get(handles.edit1,'String')
would be an mx1 cell array where m is the number of lines in the edit box. That's why, whenever I call the above on edit boxes which are single lines, I always wrap the get in a char
char(get(handles.edit1,'String'))
so that the result is in fact a string (or char array).
  1 Comment
Nick Counts
Nick Counts on 10 Oct 2014
Thanks for the reply. I suppose it could be intended, but I don't know why to be consistent it wouldn't always return a cell. A single line would just be a 1x1 cell containing a string. That way all behavior would be consistent?
It breaks the other way too, right? If you always wrap in a cell, then you can end up with a cell containing a cell, then indexing can break.
Either way, there has to be a conditional

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!