Dynamic matrix with loop
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponses (3)
Jan
le 21 Sep 2013
Modifié(e) : Jan
le 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.
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!