How to replace range in matrix with specific value?

3 visualizaciones (últimos 30 días)
Ilan
Ilan el 18 de Mayo de 2023
Comentada: Ilan el 18 de Mayo de 2023
Hi,
I have for example a matrix:
A= [1 2 3; 2 3 4, 4 5 6]
1 2 3
2 3 4
4 5 6
how do I replace all values in col 1 and 2 to 5 so it would be
5 5 3
5 5 4
5 5 6
Thanks

Respuesta aceptada

DGM
DGM el 18 de Mayo de 2023
You can do that like so:
A = [1 2 3; 2 3 4; 4 5 6];
A(:,1:2) = 5
A = 3×3
5 5 3 5 5 4 5 5 6

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by