obtain specific components of a matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello
I have a TKE_t matrix with dimensions 104*19000 , and I need to obtain values in the following order
1 14 27 40 53 66 79 92
2 15 28 41 54 67 80 93
3 16 29 42 55 68 81 94
......
13 26 39 52 65 78 91 104
ı can obtain the first one by following code:
TKE_d1=zeros(8,1);
for r=1:8
TKE_d1(r,:)=TKE_t(13*r-12,:);
end
and I can repeat the same code by changing 13*r -12 to 13*r-11 and so on to obtain other values but how I can write one code to do this ? I thought of a 2 varaible for-loop but ı couldnt make it work...
댓글 수: 0
채택된 답변
the cyclist
2019년 10월 30일
편집: the cyclist
2019년 10월 30일
M = 8;
N = 13;
L = 19000;
TKE_d = reshape(permute(reshape(TKE_t,N,M,L),[2,1,3]),M*N,L);
where
TKE_t=transpose(TKE);
as you defined in your code. I defined those parameters because I was testing on smaller cases, and also to illustrate how it generalizes.
추가 답변 (3개)
the cyclist
2019년 10월 25일
편집: the cyclist
2019년 10월 25일
TKE_d = reshape(TKE_t,[13 8 19000]);
This will result in a 3-dimensional array, each "slice" of which is like one of the matrices you want to create. Then
TKE_d(1,:,:)
will be
TKE_t([1 14 27 40 53 66 79 92],:)
(but you may need to reshape again to get what you want).
댓글 수: 4
the cyclist
2019년 10월 29일
Your question continues to be unclear to me. Here are things that are not clear:
- What size/shape is your input? Is it a 104x19000 matrix?
- How many variable are in the output? Just one variable? Or more than one variable?
- What is the size/shape of the output variable(s)?
I still think you might just be able to use the reshape command, and maybe the transpose command?
You seem to have ignored my suggestion to use my example of a very small array:
TKE_t = reshape(1:30,[6 5])
TKE_t =
1 7 13 19 25
2 8 14 20 26
3 9 15 21 27
4 10 16 22 28
5 11 17 23 29
6 12 18 24 30
This is a 6x5 matrix (instead of your 104x19000 matrix). But can you explain EXACTLY what you want for output, if this was the input? Or maybe that doesn't make sense.
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!