With help I was able to create a non-scalar structure in order to automate the multiple calculations for a regression of sinwaves with a data set of runs scored of my favorite baseball team over 501 days with a sample of 1 day. See example code:
%My inputs
y = Score(:);n = 501;sincos = rand(151,1) %what I need to mulitply the sin/cos with from identified cycles in a spectral analysis done prior%
games = 1:501;%pre-allocate structure
data(1:151) = struct('X',NaN(501,3),'bhat',NaN(3,1),'yhat',NaN);%loop
for ii = 1:151tmp = 2*pi*(sincos(ii))*n;data(ii).X = rand(501,3);data(ii).X(:,2) = cos(tmp)';data(ii).X(:,3) = sin(tmp)';data(ii).bhat = data(ii).X\y;data(ii).yhat = data(ii).bhat(1)+data(ii).bhat(2)*cos(tmp)+data(ii).bhat(3)*sin(tmp);end
My questions is now how do I plot the newly calculated sinwaves that now fit the data and automate that process for all 151 sinwaves?
When I was doing the calculations manually I was entering:
plot (n,y,'b');hold onplot (games,yhat(1),'r');plot (games,yhat(2),'g');plot (games,yaht(3),'y'); etc...etc...
I'm not clear how to automate this plotting process as well as pull the data I need from the newly created data structure. I'd hate to have to type the same line over and over 151 times!
Best Answer