필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Jason
Jason 2016년 3월 10일
댓글: Jason 2016년 3월 15일
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
.....................................................
.....................................................

채택된 답변

Ced
Ced 2016년 3월 10일
편집: Ced 2016년 3월 10일
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
Ced
Ced 2016년 3월 11일
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 2016년 3월 15일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by