how can i creat an sub array with last n number of column of an array?

2 vues (au cours des 30 derniers jours)
jakaria babar
jakaria babar le 21 Déc 2018
Commenté : jakaria babar le 22 Déc 2018
s =
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
a =
3 4 5
8 9 10
13 14 15
i am not getting 'a' using the code
A=s(1:n;end-n-1:end).

Réponse acceptée

madhan ravi
madhan ravi le 21 Déc 2018
Modifié(e) : madhan ravi le 21 Déc 2018
By indexing you can achieve it :
s= [1 2 3 4 5
6 7 8 9 10
11 12 13 14 15];
n = 3 ; % last n number of columns
a = s(:,n:end)
Gives:
a =
3 4 5
8 9 10
13 14 15

Plus de réponses (2)

Walter Roberson
Walter Roberson le 21 Déc 2018
s(end-n+1:end,end-n+1:end)

jakaria babar
jakaria babar le 21 Déc 2018
I want to built a function of creating a n by n subarray of bottom right of an array of any dimension.

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by