Could anyone help me how to change the values in array

1 visualización (últimos 30 días)
jaah navi
jaah navi el 8 de Oct. de 2019
Comentada: Adam Danz el 8 de Oct. de 2019
I ma having two array
A=[1 2
3 4
5 6];
B=[1 2];
I want to change the values present in rows of A which are not equal to B in the following manner
A=[1 2;
1 2;
1 2]
Could anyone please help me on it.

Respuesta aceptada

Adam Danz
Adam Danz el 8 de Oct. de 2019
Editada: Adam Danz el 8 de Oct. de 2019
A=[1 2
3 4
5 6];
B=[1 2];
A = repmat(B,size(A,1),1)
or
A = B .* ones(size(A))
  2 comentarios
jaah navi
jaah navi el 8 de Oct. de 2019
when i used the command line A = repmat(B,size(A,1),1),it gives the following result A=[1 2;
1 2;
1 2]
IS it possible to change the rows of A one by one
First A=[1 2;
1 2;
5 6]
then A=[1 2;
1 2;
1 2]
Could you please help me on this.
Adam Danz
Adam Danz el 8 de Oct. de 2019
That could be done in a loop, though it's not clear why this would be beneficial.
A=[1 2
3 4
5 6];
B=[1 2];
for i = 1:size(A,1)
A(i,:) = B;
end
Is that what you're looking for?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by