Filter löschen
Filter löschen

Zero out values ​​from a specific row in a matrix

13 Ansichten (letzte 30 Tage)
Lev Mihailov
Lev Mihailov am 24 Feb. 2022
Kommentiert: Jan am 24 Feb. 2022
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 Kommentar
Jan
Jan am 24 Feb. 2022
Does "reset" means, to set the value to 0? A small example with inputs and output would clarify this.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

DGM
DGM am 24 Feb. 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))
c = 1×10
5 5 8 8 7 6 5 7 7 7
x = rand(sz);
% above
xa = zeros(sz);
for col = 1:sz(2)
xa(c(col):end,col) = x(c(col):end,col);
end
xa
xa = 10×10
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.6705 0.3275 0 0 0 0 0.8203 0 0 0 0.3977 0.2444 0 0 0 0.2563 0.6388 0 0 0 0.3504 0.4670 0 0 0.8608 0.6775 0.7311 0.6058 0.9829 0.5098 0.2348 0.4727 0.5051 0.7958 0.2300 0.5589 0.2007 0.7440 0.6406 0.1086 0.3023 0.2689 0.6540 0.5244 0.9616 0.0880 0.9428 0.1761 0.6237 0.5623 0.7242 0.2876 0.3713 0.6931 0.6045 0.1354 0.0207 0.3005 0.6675 0.9878
% below
xb = zeros(sz);
for col = 1:sz(2)
xb(1:c(col),col) = x(1:c(col),col);
end
xb
xb = 10×10
0.2351 0.8935 0.6577 0.1085 0.7050 0.7653 0.5715 0.1200 0.3469 0.8277 0.8900 0.0832 0.3699 0.4257 0.3712 0.8449 0.8821 0.3460 0.0425 0.6749 0.7048 0.9170 0.8989 0.5342 0.1087 0.4904 0.3728 0.1454 0.6048 0.0438 0.9782 0.3588 0.9342 0.3823 0.5303 0.7890 0.3342 0.0637 0.2030 0.5178 0.6705 0.3275 0.4531 0.0285 0.0355 0.8376 0.8203 0.1705 0.6936 0.4366 0 0 0.6351 0.0355 0.8810 0.2563 0 0.7491 0.8071 0.5694 0 0 0.1182 0.9483 0.8608 0 0 0.6058 0.9829 0.5098 0 0 0.5051 0.7958 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by