if any variables empty in workspace, continue?

4 ビュー (過去 30 日間)
Michael
Michael 2015 年 6 月 12 日
編集済み: Stephen23 2015 年 6 月 12 日
There have been times when this would be useful...
How can I continue in a for loop to the next index when any variable in the workspace is empty?
something like:
if isempty(anyvar) == 1;
continue
end

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 6 月 12 日
you can use while loop
while isempty(anyvar)
your code
end
  3 件のコメント
Michael
Michael 2015 年 6 月 12 日
although, there doesn't seem to be a working function 'anyvar'...
Stephen23
Stephen23 2015 年 6 月 12 日
編集済み: Stephen23 2015 年 6 月 12 日
Often when people are trying to create or access lots of variables in a workspace this is a sign of poor coding practices, such as dynamically naming variables using eval.
Good programming practices actually keep quite a tight control on variables' names and their existence, so it should never be necessary to reference all variables without knowing what they are in advance.
Why not keep those variables together in some container like a cell array or structure? Most likely this would make the code much simpler, and let you use simple, standard functions and code practices, such as
cellfun('isempty',X)
However if you really want to do this, you should check out the function whos.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by