!!!Very challenge - copy one row to following two row
2 ビュー (過去 30 日間)
古いコメントを表示
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
.....................................................
.....................................................
0 件のコメント
採用された回答
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
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)')
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!