MATLAB: Saving workspace variables into one struct

structworkspace

I have a workspace containing
date (178x1 cell)
opposing_team (178x1 double)
team (178x1 double)
win (178x1 double)
I want to merge these variables into 1 struct. I tried using this code here
data = struct('date',{''},'opposing_team',[],'team',[],'win',[]);
but it deletes the data inside it, so when I open the variables it returns with a blank table. How do I create a struct that will keep the data inside? Thanks in advance.

Best Answer

Here are the two main options. First we will use this fake data:
>> date = num2cell(randi(365,178,1));
>> oppt = rand(178,1);
>> team = rand(178,1);
>> win = rand(178,1);
Non-Scalar structure of with scalar fields:
>> S = struct('date',date,'oppteam',num2cell(oppt),'team',num2cell(team),'win',num2cell(win));
>> size(S)
ans =
178 1
>> S(1)
ans =
scalar structure containing the fields:
date = 25
oppteam = 0.17320
team = 0.82512
win = 0.46835
Scalar structure with non-scalar fields:
>> S = struct('date',{date},'oppteam',oppt,'team',team,'win',win);
>> size(S)
ans =
1 1
>> S.date{1}
ans = 25
>> S.oppteam(1)
ans = 0.17320
>> S.team(1)
ans = 0.82512
>> S.win(1)
ans = 0.46835