!!!Very challenge - copy one row to following two row

3 views (last 30 days)
I have a excel file, in row 11, I have some headers. A11 is Date, B11 is Time, C11-G11 is P1 to P5. Starts row 12, there are data.
I want to copy one row data to following two row, like copy Time 0:00:00 copy to 0:05:00, 0:10:00. copy time 0:15:00 to 0:20:00, 0:25:00.
I have example as following.
A B C D E F G
11 Date Time P1 P2 P3 P4 P5
12 1/12/2016 0:00:00 1 1 No No No
13 1/12/2016 0:15:00 2 2 Yes Yes Yes
14 1/12/2016 0:30:00 3 3 No No No
. 1/12/2016 0:45:00 ..........................
. 1/12/2016 1:00:00 ..........................
. 1/12/2016 1:15:00 ..........................
.....................................................
.....................................................
107 1/12/2016 23:45:00 .........................
A B C D E F G
11 Date Time P1 P2 P3 P4 P5
12 1/12/2016 0:00:00 1 1 No No No
13 1/12/2016 0:05:00 1 1 No No No
14 1/12/2016 0:10:00 1 1 No No No
15 1/12/2016 0:15:00 2 2 Yes Yes Yes
16 1/12/2016 0:20:00 2 2 Yes Yes Yes
17 1/12/2016 0:25:00 2 2 Yes Yes Yes
.....................................................
.....................................................

Accepted Answer

Ced
Ced on 10 Mar 2016
Edited: Ced on 10 Mar 2016
Well, once you have the data in matlab ( use xlsread ), let's say in matrix A, you could do:
[N_rows, N_cols] = size(A);
A = reshape(repmat(A,1,3)',N_cols,[])';
After that, all you need to do is replace the time, e.g.
A(:,2) = (0:5:(N_rows-1)*5)';
If you import the data in minutes.
The first operation is a bit hard to explain in words, but I'll try:
1. Copy the data, twice. (repmat)
2. But I want the data below, not on the side! So I transpose, tell matlab to cut to a new column after N_cols steps. (reshape)
3. Now the data is ordered correctly, but still transposed, so transpose back. ()'
Done!
*EDIT* : Adjusted typo in repmat as pointed out below.
  5 Comments
Ced
Ced on 11 Mar 2016
just before the assignment, can you try this and tell me what the output is?
disp('size A')
size(A(:,2))
disp('size t')
size((0:5:(N_rows-1)*5)')
Jason
Jason on 15 Mar 2016
Sorry for the late reply. I just saw your reply. I did not get notified when you replied.
disp('size A')
size(A(:,2))
disp('size t')
size((0:5:(N_rows-1)*5)')
size A
ans =
9 1
size t
ans =
3 1

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!