A=[1;2;3;4;5]
i wanna add 0 to n row..i tried A(n, :) = 0...but i get this A=[0;2;3;4;5] instead of A=[0;1;2;3;4;5]
what's the problem?

 Respuesta aceptada

KSSV
KSSV el 11 de En. de 2022
Editada: KSSV el 11 de En. de 2022
Note that you want to append zero before to the first element of A. What you did is replace the first element of A with 0.
A=[1;2;3;4;5] ;
A = [0;A]
A = 6×1
0 1 2 3 4 5

3 comentarios

arian hoseini
arian hoseini el 11 de En. de 2022
i think u didnt read my explanation accurately or maybe i didnt explain my problem well... what if i want to add 0 to speific row ....if n=2
add 0 to second row ...A=[1;0;2;3;4;5]
KSSV
KSSV el 11 de En. de 2022
Editada: KSSV el 11 de En. de 2022
You check the output you have shown. In the output you have appended zero. You shuld not say adding at specific position, what you are doing is inserting. The procedure is same.
A = [1;2;3;4;5]
A = 5×1
1 2 3 4 5
n = 2 ;
A = [A(1:n-1) ; 0 ; A(n:end)]
A = 6×1
1 0 2 3 4 5
arian hoseini
arian hoseini el 11 de En. de 2022
A=[1;2;3;4;5]
add rows 2 and 5 to A to create B=[1;0;2;3;4;0;5]
A_temp=A;
index_rows=[2;5]
for i=1:size(index_rows,1)
mat1=A_temp(1:index_rows(i)-1);
mat2=A_temp(index_rows(i):end);
A_temp=[mat1;0;mat2];
end
B=A_temp;
i found the solution

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Productos

Versión

R2016b

Preguntada:

el 11 de En. de 2022

Editada:

el 11 de En. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by