输出多个单元格数组

时间:2017-02-22 09:22:33

标签: matlab cell-array

我按如下方式连接了单元格数组:

data = {5x1 cell} {1x1 cell} {0x1 cell}

这个命令data {:}给了我:

ans = 

    'MR619_01_XR'
    'MR629_01_XR'
    'MR639_01_XR'
    'MR645_01_XR'
    'MR659_01_XR'


ans = 

    'MR511_01_XR'


ans = 

   Empty cell array: 0-by-1

如何使用for循环或其他方法输出内容,如下所示:

MR619_01_XR
MR629_01_XR
MR639_01_XR
MR645_01_XR
MR659_01_XR
MR511_01_XR
NULL

由于

1 个答案:

答案 0 :(得分:3)

temp=cellfun(@isempty,data); %Finding where empty elements are
data(temp)={'NULL'};         %Changing those indexes with 'NULL'
req = vertcat(data{:})       %Concatenating vertically

%For your data, it gives:
%req = 

% 'MR619_01_XR'
% 'MR629_01_XR'
% 'MR639_01_XR'
% 'MR645_01_XR'
% 'MR659_01_XR'
% 'MR511_01_XR'
% 'NULL'