1. 判断变量存在 —— exist()
clear all; clc; close all; warning off;
a = '100';
exist('a');
%%%%%%% ans = 1
clear all; clc; close all; warning off;
a = '100';
clear a;
exist('a');
%%%%%%% ans = 0
clear all; clc; close all; warning off;
a = '100';
clear a;
~exist('a'); % 不存在用 ~exist,'~'表示取反
%%%%%%% ans = 1
区分下面四种写法:
2. 判断数组为空 —— isempty()