MATLAB: Vectorization with two dimensions at the same time

MATLABmatrixmatrix arrayvectorization

I have 2x10x10 matrix.
ans(:,:,1) =
1 3 5 7 9 11 13 15 17 19
2 4 6 8 10 12 14 16 18 20
ans(:,:,2) =
21 23 25 27 29 31 33 35 37 39
22 24 26 28 30 32 34 36 38 40
...
a(:,:,9) =
161 163 165 167 169 171 173 175 177 179
162 164 166 168 170 172 174 176 178 180
a(:,:,10) =
181 183 185 187 189 191 193 195 197 199
182 184 186 188 190 192 194 196 198 200
I want to erase the certain column of each 10 2D matries.
The rule is simple, on case of the first 2D matrix, erase first column. And second matrix, erase second column. Proceed diagonally.
If i implement this idea into for loop, it would be
for i=1:10
a(:,i,i)= [];
end
As I checked, it doesn't work. MATLAB produces the error saying "a null assignment can have only one non-colon index".
If above code works, then result should be like 2x9x10 matrix.
ans(:,:,1) =
3 5 7 9 11 13 15 17 19
4 6 8 10 12 14 16 18 20
ans(:,:,2) =
21 25 27 29 31 33 35 37 39
22 26 28 30 32 34 36 38 40
...
a(:,:,9) =
161 163 165 167 169 171 173 175 179
162 164 166 168 170 172 174 176 180
a(:,:,10) =
181 183 185 187 189 191 193 195 197
182 184 186 188 190 192 194 196 198
After writing, It looks like there are two questions about it.
  1. How can I assign null array by using two indices (`a(:,i,i)`)?
  2. And how can I vectorize it?
In vectorization, I also tried the pythonic way, but it didn't work.
a(:, 1:10, 1:10) = []; % a null assignment can have only one non-colon index

Best Answer

How can I assign null array by using two indices (`a(:,i,i)`)?
You cannot. The way you would get what you're after here is as follows.
[m,n,p]=size(a);
a(:,1:n+1:end)=[];
a=reshape(a,m,[],p)