Zero out values from a specific row in a matrix
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I create a matrix, I need to reset all values above or below a certain line
c = randi([50 90],1,900); % rows in the matrix before or after which you need to reset everything
x = rand(100,900);
I would appreciate any help
1 commentaire
Jan
le 24 Fév 2022
Does "reset" means, to set the value to 0? A small example with inputs and output would clarify this.
Réponse acceptée
DGM
le 24 Fév 2022
Depends if you want before or after. Since there's no specified mechanism to determine which, I'm assuming they're separate cases.
% a smaller array
sz = [10 10];
c = randi(round([0.5 0.9]*sz(1)),1,sz(2))
x = rand(sz);
% above
xa = zeros(sz);
for col = 1:sz(2)
xa(c(col):end,col) = x(c(col):end,col);
end
xa
% below
xb = zeros(sz);
for col = 1:sz(2)
xb(1:c(col),col) = x(1:c(col),col);
end
xb
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!