Quantcast
Channel: Programmers Heaven Forums RSS Feed
Viewing all articles
Browse latest Browse all 2703

Loop Iteration problem

$
0
0
Hi,
I am trying to do a simple matlab program and screwing up.
I have a csv file of hourly data for 1 year. Data have 0hr to 22 hr for each day ~ 23 hrs data.
So I need to copy 22nd row to 23rd row to make it ~ 24 hrs data. Then again start the counter to 0th row of 2nd day.
I could do the copying for 1 day but running the loop for whole dataset, I believe there I am messing up.

CODE:
[filename1, pathname1] = uigetfile('*.csv');

data1 = load (filename1);

% create matrices
new1= zeros(24,8);
big= zeros(48,8);

% initial counters
ri=1;
re=24;
km=24;
rt=23;
% k=1;
for i=1:48
for j=1:8
% here it does copy the 22nd row for 8 columns to 23rd row
for r=ri:re % counter for row
for c=1:8 % counter for columns
for k=1:24
new1(k,c)= data1(r,c);
if k==24 % copying 22nd row to 23rd row
new1(km,c)= data1(rt,c);
end
end
end
end
% afterwards I don't know how to do it repeatedly
% below I tried copying all data to another file and then
% re-initialze counters, but it's not working
big(i,j)= new1(k,j);
ri=1+23;
re=24+23;
km=24;
rt=23+23;
end

end

Attached is a sample dataset.
please help me out.

Viewing all articles
Browse latest Browse all 2703

Trending Articles