Problem 7. Column Removal
Solution Stats
Problem Comments

21 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 singlecolumn 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/removingrowsorcolumnsfromamatrix.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).
Solution Comments

1 Comment
so easy

2 Comments
good problem
GOOD

1 Comment
GOOD

2 Comments
nice
innovative problem

1 Comment
These problems really test our knowledge.

1 Comment
function B = column_removal(A,n)
c=A'
c(n,:)=[]
A=c'
end
Why does my code solve the problem, but it is explicitly an error?

1 Comment
Remember to use () & [] correctly.

1 Comment
super task

4 Comments
A(:,n)=[];
B=A
Very good. I am new to Matlab. Thanks Mr. Piero Cimule.
Thanks!
great job

1 Comment
B = horzcat(A(1:end,1:n1), A(1:end,n+1:end)); gives size 35.
How can we know the real leading solution sizes if there are those "message solutions" that are not real solutions?

1 Comment
please delete this solution

1 Comment
woooooooow! good job

1 Comment
I really need to learn to code better. I say this because I keep on getting size which is atleast 23 times the size of the leading solution.

1 Comment
larger size but will work for n=1

1 Comment
This would fail for n=1

2 Comments
VERY EASY
good stuff

1 Comment
good

1 Comment
B(n)=A[] ?

1 Comment
What am I doing wrong? Im new btw. Learning the basics.

1 Comment
What is the best optimized solution for this particular problem? Could someone with size 19 or smaller please indicate their solutions. Thanks

1 Comment
My code solves the problem, yet I get incorrect answer

1 Comment
Good one.

1 Comment
no need to use for loop or anything.
it's just this.

2 Comments
nice, I wish I had thought of it this way
nice

2 Comments
can anybody tell me why this solution is not working:"[a,b] = qr(A);
[a1,b1] = qrdelete(a,b,n);
y = a1*b1;"
Although it gives right answers to all test Suits in the software.Plz
because of rounding errors.
B = round(a1*b1);
it should work in this case as all numbers are integers.

2 Comments
B=A(:,1:end1);
What is wrong here?
you are just removing the "last" column, not the "nth" column.

1 Comment
I've checked this coding:"[a,b] = qr(A);
[a1,b1] = qrdelete(a,b,n);
B = a1*b1;" Why this not working??? Can anybody check this....

1 Comment
Hi, this code working good. then how to say it is incorrect?

1 Comment
妙啊

1 Comment
Why the following solution doesn't work? It does on my MATLAB 2011a :
function B = column_removal(A,n)
if((n < 1)  (n > size(A, 2)))
B = A;
return;
end
if(n > 1)
l = A(:, 1:(n1));
else
l = [];
end
if(n < size(A, 2))
r = A(:, (n+1):size(A, 2));
else
r = [];
end
B = [l,r];
end

2 Comments

1 Comment
oops ! didn't read the requirements right

1 Comment
i`m not really sure [] is faster than '' but is good to know

1 Comment
it seems that A(:,n)='' is a bit faster than A(:,n)=[]; but usually we use the latter one,

1 Comment
I can't believe it is this simple. lol.

5 Comments
Dear Oscar,
in comparison to your code, the below implementation is much faster but your style of code is a crack to cody system, well done.
function A = column_removal(A,n)
A(:,n) = '';
end
Dear Sadid, I agree with you that my implementation is completely stupid and a waste of time in real life and that's why I don't like the current evaluation metric of Cody. A (time and/or memory)based evaluation would be much more interesting. With the current evaluation metric, Cody promotes hacking and cracking (which is also fine), but players don't learn good manners for developing efficient code.
NICE ONE BUT BIT DIFFICULT
@Óscar yes, you are right. the player can't study the one with well written style
agreed with Oscar

1 Comment
My MATLAB 2012a worked for #2

6 Comments
What happened to "and return the resulting matrix in output B"?
Strange: A(:,n) = [] has size 15 but is basically the same?
How safe is this to do?
function ans = column_removal(A,n)
A(:, n) = ''
end
Why doesn't this code work? :/
@Mechatrobrnotronik: I tested your code.
function ans = test_fkt(A,n)
A(:,n) = ''
end
Works for me. Returning A with removed column n.
Nonetheless I am interested in what '' actually does. I couldn't find it in the command reference.
fun

2 Comments
Can the server provide more information on failed solution?
For those who wonder how such low scores are being reported in Cody, it is because many players are changing the actual function call. The result is obvious to those of us who have solved many of these challenges.
Problem Recent Solvers20865
Suggested Problems

1808 Solvers

Back to basics 8  Matrix Diagonals
848 Solvers

609 Solvers

653 Solvers

6783 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!