Debugging help needed please :(

조회 수: 1 (최근 30일)
chlor thanks
chlor thanks 2016년 7월 15일
댓글: chlor thanks 2016년 7월 19일
I am trying to have a loop that extracts all files that do not start with ~$ and ends in xls or xlsx
This is what I have
n = length(list);
%list is an cell array of a list of folders that I have
i = 0; ii=0;
for k = 1 : n
Sub = list{k};
filehunt = fullfile(Sub, '*.xls*');
Excel = dir(filehunt);
%here I use the loop to "dir" all files that contain the keywords .xls
if ~isempty(Excel)
for k2 = 1 : length(Excel)
ii=ii+1;
if strncmp('~$',Excel(k2).name,2)== 0
goodexcel(ii)=Excel(k2).name;
%here I try to eliminate any files that have ~$ in front
if ~isempty(goodexcel)
for k3 = 1 : length(goodexcel)
i=i+1;
if ~isempty(regexp(goodexcel(k3).name, '\.xlsx?$', 'once'));
ExcellentExcel(i)=goodexcel(k3).name
%here I try to find all files that end in xls or xlsx instead of just having .xls somewhere in the file name
end
end
end
end
end
end
end
This has not been able to work due to the error:
Subscripted assignment dimension mismatch.
Please enlighten my poor brain with any matlab coding skill/tips.
Thank you for your patience.

채택된 답변

Image Analyst
Image Analyst 2016년 7월 15일
편집: Image Analyst 2016년 7월 15일
Check this out:
if all(Excel(k2).name(1:2) == '~$')
msgbox('It starts with ~$ so skip this file');
break; % Skip to bottom of loop
else
msgbox('It does not start with ~$');
end
  댓글 수: 9
Image Analyst
Image Analyst 2016년 7월 19일
You can use fileparts() to pull off the last extension
[folder, baseFileNameWithoutExtension, extension] = fileparts(filename);
Then just use extension to see whether to add to the final list.
chlor thanks
chlor thanks 2016년 7월 19일
Although I still have not able to figure out how to get rid of the empty cells returned by the loop. The fileparts() command works great and better than the regexp() I was trying with before. Thank you very much for the helpful info!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by