How to modify xlsread to get a step-by-step updated flag from loading process

I have installed Matlab r2010a on my computer

I need use the function xlsread to load data from one just one *.xls or *.xlsx file. that's not a big challenge, the problem is How to modify xlsread.m to get a flag (integer) that gives the percentage of the loading process?

Thanks a lot.

so far i made this: put a step variable to count until half then call xlsread that take a little time and after load process, the counter in 49.5% count to the end.

Not the best, but this is what I have

file = 'example.xls';

h = waitbar(0, ['Loading data from ' file], ...
            'Name', 'Loading',...
            'CreateCancelBtn',...
            'setappdata(gcbf, ''canceling'', 1)');

steps = 200;

for step = 1 : steps

    %# Check for Cancel button press

    if getappdata(h, 'canceling')
        okCancel = 1;
        break
    end

    pause(0.01);         %# Delay time for wait bar progres

    if step == steps/2
        [data, txt] = xlsread(file);
    end

    %# Process status report

    waitbar(step/steps, h, sprintf(['Loading data from file... %3.2f%%'], step*100/steps));
end

set(h, 'CloseRequestFcn', 'closereq')
close(h)


ANSWERS:


XLSREAD function allows you to specify ranges of cells to read. Therefore you could read your data in batches (say read the first 50 rows of the table, then the next 50, and so on), each time "incrementing" the progress bar.

Note that this will be slower than reading the whole table at one, because the function has to make a connection to Excel COM then tear it down each time it is called (see this post for an explanation and a possible solution).


EDIT:

Here is a quick example:

%# path to excel file to read
fname = fullfile(pwd,'test.xls');

%# get number of rows/columns in table
Excel = actxserver('Excel.Application');    %# open Excel COM Server
wb = Excel.Workbooks.Open(fname, 0, true);  %# open XLS file for reading
sheet = Excel.Worksheets.get('item',1);     %# activate first sheet
numRows = sheet.Range('A1').End('xlDown').Row;
numCols = sheet.Range('A1').End('xlToRight').Column;
wb.Close(false);                            %# close XLS file
Excel.Quit();                               %# cleanup
Excel.delete();
clear Excel wb sheet;

%# read rows in steps, and show progress-bar
numSteps = 20;
idx = fix(linspace(0,numRows,numSteps+1));
num = cell(numSteps,1);
h = waitbar(0, 'Reading excel file');
for i=1:numSteps
    %# update progress-bar
    waitbar(i / numSteps);

    %# range of cells to read
    cellRange = sprintf('%c%d:%c%d', ...
        'A', idx(i)+1, char('A'+numCols-1), idx(i+1));
    num{i} = xlsread(fname, 1, cellRange);
end
close(h)

%# merge all cells into a matrix
num = cell2mat(num);

screenshot

This assumes the Excel file contains a table of numeric data. Feel free to adapt to your own file.



 MORE:


 ? How can I make waitbar in MATLAB modal
 ? Get waitbar value in Matlab
 ? waitbar matlab before start a standalone script
 ? matlab progress bar not depanding on time
 ? JavaFX ProgressBar/ProgressIndicator: listen for change from multiple Sliders
 ? JavaFX ProgressBar/ProgressIndicator: listen for change from multiple Sliders
 ? JavaFX ProgressBar/ProgressIndicator: listen for change from multiple Sliders
 ? JavaFX ProgressBar: how to add an animation?
 ? JavaFX ProgressBar problems
 ? JavaFX ProgressBar Wont Reset