How do I remove any Column in a matrix
Mostrar comentarios más antiguos
Please what is wrong with this function. I want it to remove 'n' column form the matrix A
function B = column_removal(A,n)
A1= A(:,1:n-1) % Index from column 1 to column 'n-1'
A2 = A(:,n+1:end) % Index from column 'n+1' to the last co1umn
B = [A1 A2] % concatenate A1 & A2 by which the n column would have been removed
end
4 comentarios
Ive J
el 14 de En. de 2021
A(:, n) = [];
Cutie
el 14 de En. de 2021
Mathieu NOE
el 14 de En. de 2021
A(:, n) = [];
means that the 'n' th column has been flushed
Cutie
el 14 de En. de 2021
Respuesta aceptada
Más respuestas (1)
ercan duzgun
el 14 de En. de 2021
Dear Cutie,
Your MATLAB function already works fine. However, Matt J's solution is simpler.
I checked your MATLAB function by this example below, and I received the expected result.
X=[1 2 3 4 5 6; 10 20 30 40 5 60;100 200 300 400 500 600]
column_removal(X,3)
A1 =
1 2
10 20
100 200
A2 =
4 5 6
40 5 60
400 500 600
ans =
1 2 4 5 6
10 20 40 5 60
100 200 400 500 600
1 comentario
Cutie
el 14 de En. de 2021
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!