Zero out values from a specific row in a matrix
4 views (last 30 days)
Show older comments
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 Comment
Jan
on 24 Feb 2022
Does "reset" means, to set the value to 0? A small example with inputs and output would clarify this.
Accepted Answer
DGM
on 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))
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 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!