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.

 채택된 답변

Walter Roberson
Walter Roberson 2018년 8월 28일

0 개 추천

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};

추가 답변 (0개)

카테고리

태그

질문:

2018년 8월 28일

댓글:

2018년 8월 28일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by