Problem 7. Column Removal
Remove the nth column from input matrix A and return the resulting matrix in output B.
So if
A = [1 2 3; 4 5 6];
and
n = 2
then B is
[ 1 3 4 6 ]
Solution Stats
Problem Comments
-
22 Comments
All solutions with score 11 or 12 use the regexp cheat.
Is there somewhere to go to receive advice on how to improve your code?
i can't think of a better solution having size less than 19!
why isn't B = (A(:,n)=[]); working? thanks
How to improvise this code?
It's very MATLAB!
this was actually not that difficult :)
a good way to learn
There should be a single-column input matrix in the test suite.
This was fun! Not difficult, but kind of challenging!
A(n,:)=[]; B = A; it works,but I'm wrong,who tell me the reason?
Better test cases could be provided for edge cases.
Great problem.
Lets you dug deep into the documentation for an awesome solution.
This link might help : https://in.mathworks.com/help/matlab/math/removing-rows-or-columns-from-a-matrix.html
Good problem
good
Good one
Why this is not working?
B = A ( : , ~=n)
I know logic operator needs something~=n but I cannot decide how to correct it? Also, I can write if statement in a for loop but its size is huge.
good
function B = column_removal(A,n)
A(:,n) = [];
B = A;
end
Can someone please tell me what is wrong with this code?
@Shivi, it does work.
The tests don't check the cases for n=1 and n=num_cols(A).
https://www.mathworks.com/help/matlab/math/removing-rows-or-columns-from-a-matrix.html
Solution Comments
Show commentsProblem Recent Solvers25346
Suggested Problems
-
1741 Solvers
-
Set the array elements whose value is 13 to 0
1369 Solvers
-
716 Solvers
-
739 Solvers
-
Find the max element of the array
1524 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!