user27976
user27976

Reputation: 903

outputting contents of multiple cell array

I have concatenated cell arrays as follows:

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

This command, data{:}, gives me:

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

How can I use for loop or another method to output the contents as follows:

MR619_01_XR
MR629_01_XR
MR639_01_XR
MR645_01_XR
MR659_01_XR
MR511_01_XR
NULL

Thanks

Upvotes: 0

Views: 48

Answers (1)

Sardar Usama
Sardar Usama

Reputation: 19689

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'

Upvotes: 3

Related Questions