Debugging help needed please :(

1 view (last 30 days)
chlor thanks
chlor thanks on 15 Jul 2016
Commented: chlor thanks on 19 Jul 2016
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)
if strncmp('~$',Excel(k2).name,2)== 0
%here I try to eliminate any files that have ~$ in front
if ~isempty(goodexcel)
for k3 = 1 : length(goodexcel)
if ~isempty(regexp(goodexcel(k3).name, '\.xlsx?$', 'once'));
%here I try to find all files that end in xls or xlsx instead of just having .xls somewhere in the file name
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.

Accepted Answer

Image Analyst
Image Analyst on 15 Jul 2016
Edited: Image Analyst on 15 Jul 2016
Check this out:
if all(Excel(k2).name(1:2) == '~$')
msgbox('It starts with ~$ so skip this file');
break; % Skip to bottom of loop
msgbox('It does not start with ~$');
chlor thanks
chlor thanks on 19 Jul 2016
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!

Sign in to comment.

More Answers (0)


Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by