MATLAB: Structfun to read the filenames

structfun

F=dir('*.nc')
for ii=1:length(F)
case_name{ii,1}=F(ii).name;
end
Can we write the above code without using loop. I have tried with strutfun, but fails to get the required result.

Best Answer

case_name = cell(length(F), 1);
case_name(:) = {F.name};
The above preserves the column-vector ordering you used. Another approach is
case_name = {F.name};
case_name = case_name(:);
or
case_name = reshape({F.name}, [], 1);
However unless you have a particular need for it to be a column vector, just use
case_name = {F.name};