Dynamic matrix with loop

1 Ansicht (letzte 30 Tage)
Trey
Trey am 21 Sep. 2013
I have a probably simple question I have not been able to solve. Yes, I've gone through the questions and the answers didn't seem to help me.
Here is the code:
clc
Feb=textread('/Users/treybuechler/Desktop/Irradiance_Data/Feb2013/data.txt');
[Time,x]=size(Feb);
second=1;
min=60*second;
hour=60*min;
day=24*hour;
day=int64(day);
num_days=(Time/day);
k=floor(num_days);
k=int64(k);
Day=zeros(1,day);
for i=0:k-1
l=(i)*day+1;
m=(i+1)*day;
Day(:,i+1)=Feb(1:m);
end
What I am trying to do is I have a text file that contains a string of numbers, data taken at every second. I want to read the data in (this works) I then get this array:
Feb 1048327x1
Now, since I don't know how much data is in each text file, I use the equations to get the number of seconds in a day..and from the data read in, find out how many days there are...Then I want to use that loop to create a matrix of data that has either a column for each day or a row for each day, preferably a column. So, I'm just taking the 'Feb' array and taking chunks and placing them in the expanding matrix Day. I have tried several different things suggested on different posts, but nothing has worked. Here is the error I get
??? Subscripted assignment dimension mismatch.
Error in ==> irradiance_data at 23
Day(:,i+1)=Feb(1:m);
and here is the list of variables if that helps at all
Name Size Bytes Class Attributes
Day 1x86400 691200 double
Feb 1048327x1 8386616 double
Time 1x1 8 double
day 1x1 8 int64
hour 1x1 8 double
i 1x1 8 int64
k 1x1 8 int64
l 1x1 8 int64
m 1x1 8 int64
min 1x1 8 double
num_days 1x1 8 int64
second 1x1 8 double
x 1x1 8 double
That should be all the information anyone needs. I didn't want to resort to posting a question, but I've run through all the things I could find.
Thank you very much.

Antworten (3)

Walter Roberson
Walter Roberson am 21 Sep. 2013
Change
Day=zeros(1,day);
to
Day = zeros(day, 1);

Trey
Trey am 21 Sep. 2013
Thanks, for the reply, I've tried that before, tried it again and receive the same error Regards.

Jan
Jan am 21 Sep. 2013
Bearbeitet: Jan am 21 Sep. 2013
At first I suggest to use the debugger to check the dimensions of the variables in the crashing line. Type this in the command window:
dbstop if error
Then start your program again. It stops when the error occurs. Then type this in the command line:
size(Day(:,i+1))
size(Feb(1:m))
Do the sizes match?
I suggest to simplify the function to e.g.:
Feb = textread('/Users/treybuechler/Desktop/Irradiance_Data/Feb2013/data.txt');
nTime = size(Feb, 1);
nDay = round(nTime / 86400);
Day = reshape(Feb(1:nDay * 86400), 86400, nDay);
Remark: The conversions to int64 are not useful in your code.
  1 Kommentar
Trey
Trey am 23 Sep. 2013
I did this and this was the result:
K>> size(Day(:,i+1)) ??? Index exceeds matrix dimensions.
K>> size(Feb(1:m))
ans =
172800 1
However, using the code you suggested it worked perfectly. THank you very much. I originally used the int conversion because i was getting errors for the contents being of type double..
So, The next question is how to get this to plot against time=86400?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by