MATLAB Concatenate matrices with unequal dimensions

后端 未结 3 1894
梦如初夏
梦如初夏 2021-01-14 07:02

Is there any easy way to concatenate matrices with unequal dimensions using zero padding?

short = [1 2 3]\';
long = [4 5 6 7]\';
desiredResult = horzcat(shor         


        
3条回答
  •  臣服心动
    2021-01-14 07:20

    Matlab automatically does padding when writing to a non-existent element of a matrix. Therefore, another very simple way of doing this is the following:

    short=[1;2;3];

    long=[4;5;6;7];

    short(1:length(long),2)=long;

提交回复
热议问题