0

I am trying to take my excel spreadsheet and import it into MATLAB (already accomplished that), and then using for-loop indexing to create arrays of the data for a give day containing.

Example of my desired output

So ideally I would like to know how I could iterate through a years worth of data, and create variables with the date corresponding to the table elements on that day. As I said, I have multiple years worth of data, which is why I'd like a solution which would "automate" my process.

Data Gathered From the Internet Into Excel

MATLAB table created from Excel Sheet

6
  • To be honest, it is not really clear what you want. I mean, you already can iterate through the dates. Do you want to dynamically name the variables? That is not a good idea. You could make a structure inside structure which has all the data: struct('date',struct('<name of data>',data,'<name of data2>',data2 Commented Aug 18, 2020 at 10:13
  • Eventually, I would like to be able to manipulate data for each day, and get totals of points for an entire day that may have 10 games on that day. My thought was if I can have a bunch of arrays I could iterate thru and find totals would be easiest. Apologies if my explanation is difficult to understand. Commented Aug 18, 2020 at 13:27
  • So you want to be able to get a mean result for a certain day, is that correct? Commented Aug 18, 2020 at 13:50
  • Yes, I've done some more research on structs, and I think ideally I'd like to create a a season struct, with dates struct housing all the games and info of each game that occurs that day Commented Aug 20, 2020 at 21:20
  • So how would I go about grouping the dates within my seasons struct into a struct named by that date, and containing all the data like teams, scores, odds, etc within the date struct? Commented Aug 20, 2020 at 21:38

1 Answer 1

0

Welcome to stackoverflow! Note that it is easier if you provide some code -- at least to create some sample data.

Anyway, you can loop over dates easily and there shouldn't be a problem with efficiency if you scale it to many entries:

Tm = [  datetime('now') + duration(1,0,0)%add 1 hour
        datetime('now')
        datetime('yesterday')
        datetime('tomorrow')];

    
% convert to date
Dt = yyyymmdd(Tm);
% you may want to sort it
% [val,idx] = sort(Dt);

% get unique dates
Dt_uq = unique(Dt);

% create a cell of storage
DataAtDate = cell(length(Dt_uq),1);

% loop over unique dates
for i = 1:length(Dt_uq)
    Dt1 = Dt_uq(i);
    % get all of the same type
    lg = Dt == Dt1;
    % index matrix/cell to do something
    disp(Dt(lg,:))
    % do something with the data or matrix or table... e.g. store it in a cell
    DataAtDate{i} = Dt(lg,:);
end

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.