Effacer les filtres
Effacer les filtres

How to take elements row wise or column wise in a 2d array

6 vues (au cours des 30 derniers jours)
MSP
MSP le 31 Déc 2016
A is a 5*5 array. Its needed to take 7 elements along the 1st column and 2 from the beginning of 2nd column.So the window size is 7.Now that makes it possible to take 3 windows.So 4 elements are left.this last window should be 4 leftover elements and rest zeroes.How to have a loop that gives me the 4 windows in a variable
  3 commentaires
MSP
MSP le 1 Jan 2017
Modifié(e) : per isakson le 1 Jan 2017
But can u pls generalize it
per isakson
per isakson le 1 Jan 2017
In your question you say
  • "a 5*5 array" &nbsp
  • "take 7 elements [window] along" &nbsp
  • "that gives me the 4 windows in a variable" &nbsp
  • "matrix signalprocess" &nbsp
"generalize" &nbsp Yes, but in what way? Arbitrary size of the input matrix and/or the window? Along columns or rows? ...

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 31 Déc 2016
  1 commentaire
Walter Roberson
Walter Roberson le 1 Jan 2017
window = 7;
A = randi(5,5);
n = numel(A);
left_over = mod(n, window);
if left_over == 0
stream = A(:);
else
stream = [A(:); zeros(window - left_over, 1)];
end
output = reshape(stream, window, []);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating 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!

Translated by