MATLAB: Need help with loops

loopsxlsread

I have written a script that reads in data from an excel file into a 4×27 matrix and then performs all the relevant analysis I need and displays results in the command window. I am happy with the script, but I have large amounts of data to run through.
All the data is in the identical form (a 4×27 matrix) but it has to be copied and pasted from a webpage into the excel sheet. At the moment I am running the script for seperate excel sheets, but would like to copy and paste multiple data sets into the excel sheet and run the script once to get all the data.
i.e. the script currently reads in rows like:
data1
data1
data1
data1
then I have to manually create another excel file/overwrite the existing file to create more data. I want it to deal with:
data1
data1
data1
data1
data2
data2
data2
data2
etc……
I feel that since I have already read the script to deal with each dataset as i desire, this shouldn't be a hard task to perform if I use loops well. I just have an almost non-existent knowledge of how to use loops.
I was hoping people could point me in the right direction.
Any help would be great thanks.
———————EDIT 1———————————-
The code I have written has now been added in the edit, as has an example of a dataset that the code reads in (i uploaded it as .xls whilst on my computer i use .xlsx)
I want the improved script to do the same job, but on an excel sheet containing multiple datasets.
——————————EDIT 2————————————
I have now uploaded a xls file of the form I wish the script to tackle. The spacing between datasets is arbitrary, and can be changed depending if it makes the job easier.

Best Answer

Rewriting the above to compute for any number of bets would seem simplest--
function [stat,mxIdx] = bestbets(odds)
% return betting odds prediction statistic and max row given odds array
C = nanmean(odds,2); %computes averages of rows
[D,mxIdx] = max(odds,[],2); %finds max value of rows
E = 1/sum(1./D); %ACE
F = 1/sum(1./C); % Mean ACE
G = C./F; % True odds
stat=zeros(size(D)); % preallocate the statistic
indx=1:length(D); % index array 1:N observations
for i=1:length(D)
stat(i,:) = 1/sum([1/D(i); 1./G(~(ix==i))])-1; % compute for each
end
Above reproduces your check array values for the given dataset.
NB: Above presumes the input odds array has been cleaned up before being passed, the problem about generating a suitable file format is a different discussion than than the algorithm implementation.
The loop could be eliminated with accumarray but left so could more easily get the implementation.
The "trick" is in building the logical addressing vector ~(indx==i) to select the elements from the G array with the exception of the one element being computed.
PS: While the computer doesn't care, as a general best practice I'd suggest using descriptive names for variables rather than just C, D, etc. It'll be bound to help in the long run as you develop into using Matlab and other programming languages more. I'll give high marks for brevity; that is also in my (nsh :) ) opinion an objective as exceedingly long variable names tend to just add clutter more than clarify, but at least some sort of a mnemonic to relate to the purpose is important for legibility.
ERRATUM Corrected order of function line to get function keyword first...
Related Question