obtain specific components of a matrix
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
the cyclist
le 30 Oct 2019
Modifié(e) : the cyclist
le 30 Oct 2019
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.
Plus de réponses (3)
the cyclist
le 25 Oct 2019
Modifié(e) : the cyclist
le 25 Oct 2019
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 commentaires
the cyclist
le 29 Oct 2019
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.
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!