Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: filling a matrix
Replies: 2   Last Post: Nov 21, 2012 12:09 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Jonathan Allan

Posts: 116
Registered: 12/7/04
filling a matrix
Posted: Nov 20, 2012 8:38 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

G'day,
I'm trying to read in hourly data from multiple years and create a matrix that incrementally adds each year of data to the same matrix. The code I have is:

j1 = [1975,1977,1978,1979,1981,1982,1983,1985,1986,1987,...
1989,1990,1991,1993,1994,1995,1997,1998,1999,2001,2002,2003,...
2005,2006,2007,2009,2010,2011]; %normal years
j2 = [1928,1932,1936,1940,1944,1948,1952,1956,1960,1964,1968,1972,...
1976,1980,1984,1988,1992,1996,2000,2004,2008,2012]; %leap years

tst=1987:1989;
N=length(tst);
A = NaN*ones(N,8784); %fill with NaNs

for m=1987:1989; % add hourly data
for j=1:N;
fname=sprintf('yaq%d.txt',m);
if any(m == j1);
data=load(fname);
Hs=data(:,5);
A(j,1:length(Hs)) = Hs;
elseif any(m == j2);
data=load(fname);
Hs=data(:,5);
A(j,1:length(Hs)) = Hs;
end
end
end

However, my code seems to be only repeating the last year of data. I know its a simple fix but I'm having a mind block. What am I doing wrong?

Thanks.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.