Implicit expansion for CAT()


Would it be a good thing to have implicit expansion enabled for cat(), horzcat(), vertcat()? There are often situations where I would like to be able to do things like this:
x=[10;20;30;40];
y=[11;12;13;14];
z=cat(3, 0,1,2);
C=[x,y,z]
with the result,
C(:,:,1) =
10 11 0
20 12 0
30 13 0
40 14 0
C(:,:,2) =
10 11 1
20 12 1
30 13 1
40 14 1
C(:,:,3) =
10 11 2
20 12 2
30 13 2
40 14 2
Bruno Luong
Bruno Luong 2024년 1월 27일
I would vote to have the auto expansion cat as default behavioir, even it will break the compatibility and it would be painful for the transition periode. I think in the long term people will get use to it just like binary operator auto-expansion introduced in 2016 (?).
Stephen23
Stephen23 2023년 11월 6일
"Would it be a good thing to have implicit expansion enabled for cat(), horzcat(), vertcat()?"
What would be great is having some kind of syntax switch to select between strict mode and expanding mode. Ditto for all of the "new" singleton expanding numeric operators. Concatenation is n-ary, but my wish still applies:
Matt J
Matt J 2023년 10월 19일 (2023년 10월 19일에 수정됨)
Bruno Luong
Bruno Luong 2024년 1월 27일
Matt J
Matt J 2024년 3월 1일
It's a remake. We've had 3 Batmans in the past 13 years as well.
Walter Roberson
Walter Roberson 2023년 10월 17일
I have more than once wanted to write something along the lines of
[Block, 0]
with the intention being that the 0 would expand to match the number of rows in the Block. When block here is a variable it isn't so bad to write
[Block, zeros(size(Block,1),1]
but if Block is an expression then we are forced to write the expression to a temporary variable for efficiency.
I personally do not tend to use cat directly for 1D or 2D data, so it would be nice if [] could recognize such a situation as well.
I do recognize, though, that there are ambiguous situations where deducing how big of a zero to insert would not go well...
[ones(1,3), 0, ones(1,3)
ones(1,2), 0, ones(1,4)]
should that be [1 1 1 0 1 1 1; 1 1 0 1 1 1 1] or should it do block size matching and "deduce" that it should be [1 1 1 0 0 1 1 1; 1 1 0 0 1 1 1 1] or something like that?
Humans can think in terms of multi-row blocks being compiled with other multi-row blocks to form a larger block that is to be combined with something else... but cat() and [] need definite algorithms on the order to put together the components...