Based on this answer, how about this:
for i = 1:5
A27_data = domain_URL{i};
s = dir(strcat('f9data\','f7_data', int2str(i)));
if s.bytes == 0
B27(i) = NaN;
else
data2 = importdata(strcat('f9data\','f7_data', int2str(i)));
feature27_data=(cellfun(@(n) ~isempty(n), strfind(data2, A27_data)));
B27(i)=sum(feature27_data);
end
end
Before loading any data, check if the file is empty or not. If it is, assign NaN
to B27(i)
(or any other default value). If the file actually contains data, run your processing on it.
Edit
If you don't like NaN
, you can do something else, e.g.:
B27(i) = 0;
Edit 2
- Stick with the
B27(i) = NaN
option. After the
if
/else
loop, insert this:if ~isnan(B27(i)) B27(i) = data2 end
After the
for
-loop, insert this:B27(isnan(B27))=0; clear data2 data2 = B27;