if any variables empty in workspace, continue?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2015년 6월 12일
you can use while loop
while isempty(anyvar)
your code
end
댓글 수: 3
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)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!