我假设你在谈论一个单元阵列.
在这种情况下,最简单的是:
%# create some sample data
C = {1,2,[];3,[],99};
%# replace empty elements with -1
[C{cellfun(@isempty,C)}] = deal(-1);
%# or, simpler (thanks @EitanT)
C(cellfun(@isempty,C)) = {-1};
%# just in case you want to turn C into a numeric array
numericC = cell2mat(C);
Run Code Online (Sandbox Code Playgroud)