to which command refers ~isempty() to?

2 次查看(过去 30 天)
Sorry for the dumb question, but I am working on a matlab code I didn't write myself and several '~isempty(<1xn> cell in here)' are occuring. Since I am relatively new to matlab and programming, I just don't understand yet to what the isempty refers. I couldn't find any satisfying answers and so i thought maybe i could find help here. The isempty is always bound to an if loop.
like:
set (handles. ...
set (handles. ...
if ~isempty(ZoneElementProtNameUnder{1,1})
set(handles.protUnder,'String',ZoneElementProtNameUnder{1,1});
else ...
So does isempty work with the 'set handles' or with the 'ZoneElement...', or even with a previous command? Or what exactly is it doing?
I appreciate any answers or help, thanks!

采纳的回答

Cedric
Cedric 2013-10-14
编辑:Cedric 2013-10-14
ZoneElementProtNameUnder is a 2D cell array. ZoneElementProtNameUnder{1,1} is the content of cell on column 1 and row 1 (curly brackets = "content of" for cell arrays). As cells can have empty content, the condition in the IF statement
if ~isempty(ZoneElementProtNameUnder{1,1})
is just checking that this cell's content is not empty. If true, then the expression
set(handles.protUnder,'String',ZoneElementProtNameUnder{1,1});
is using the content.

更多回答(1 个)

Walter Roberson
Walter Roberson 2013-10-14
In that code, ZoneElementProtNameUnder is a cell array that has at least one element. To access just that one element unwrapped from the cell array, you would code ZoneElementProtNameUnder{1,1} . If the entity that is stored there is empty, then isempty(ZoneElementProtNameUnder{1,1}) would be true, and ~isempty(ZoneElementProtNameUnder{1,1}) would be false; contrawise if ZoneElementProtNameUnder{1,1} had something in it, then isempty(ZoneElementProtNameUnder{1,1}) would be false and ~isempty(ZoneElementProtNameUnder{1,1}) would be true.
  2 个评论
Manuel Olschner
Manuel Olschner 2013-10-14
that explains it very well, thank you!
Jan
Jan 2013-10-14
@Cedric and Walter: I appreciate your clear explanations of this basic question.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by