Zero out values from a specific row in a matrix
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lev Mihailov
el 24 de Feb. de 2022
Comentada: Jan
el 24 de Feb. de 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 comentario
Jan
el 24 de Feb. de 2022
Does "reset" means, to set the value to 0? A small example with inputs and output would clarify this.
Respuesta aceptada
DGM
el 24 de Feb. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!