Here's how you can add zeros to the beginning and end of your signal (with the extra zero going to the end in case the number of zeros needed is odd - as you appear to have it):
SignalLength = length(Signal);
Nzeros = Lmax-SignalLength;
Signal = [zeros(1,(Nzeros-1)/2), Signal, zeros(1,(Nzeros+1)/2)];
Signal = [zeros(1,Nzeros/2), Signal, zeros(1,Nzeros/2)];
disp(Signal);
0 0 0.8021 0.0218 0.9967 0.1352 0 0 0
Or, using a variable Nzeros_mod2 = mod(Nzeros,2) instead of the if/else construction:
SignalLength = length(Signal);
Nzeros = Lmax-SignalLength;
Nzeros_mod2 = mod(Nzeros,2);
Signal = [zeros(1,(Nzeros-Nzeros_mod2)/2), Signal, zeros(1,(Nzeros+Nzeros_mod2)/2)];
disp(Signal);
0 0 0.0974 0.4638 0.7127 0.5242 0 0 0
Another example, where the number of zeros is even:
SignalLength = length(Signal);
Nzeros = Lmax-SignalLength;
Nzeros_mod2 = mod(Nzeros,2);
Signal = [zeros(1,(Nzeros-Nzeros_mod2)/2), Signal, zeros(1,(Nzeros+Nzeros_mod2)/2)];
disp(Signal);
0 0 0.7752 0.4344 0.5274 0.7130 0 0
Notice that your expression will work only when the number of zeros is odd, i.e., when one of Lmax and SignalLength is odd and the other is even. In case they are both even or both odd, then their difference is even and you'd get an error using the zeros function because (Lmax-SignalLength+1)/2 is not an integer:
SignalLength = length(Signal);
zeros(1,(Lmax-SignalLength+1)/2)
end
Size inputs must be integers.
However, this is not the error message you report in the title of the question. The error message, "Dimensions of matrices being concatenated are not consistent." in this context would suggest that your signal is not of size 1 in dimension 1 most likely:
SignalLength = length(Signal);
Nzeros = Lmax-SignalLength;
Nzeros_mod2 = mod(Nzeros,2);
Signal = [zeros(1,(Nzeros-Nzeros_mod2)/2), Signal, zeros(1,(Nzeros+Nzeros_mod2)/2)];
end
Dimensions of arrays being concatenated are not consistent.
To add zeros to the beginning and end of a signal with size other than 1 in dimension 1, take that into account in calling the zeros function:
SignalLength = size(Signal,2);
Nzeros = Lmax-SignalLength;
Nzeros_mod2 = mod(Nzeros,2);
Signal = [zeros(Nrows,(Nzeros-Nzeros_mod2)/2), Signal, zeros(Nrows,(Nzeros+Nzeros_mod2)/2)];
disp(Signal);
0 0 0.4438 0.8402 0.1166 0.8648 0 0
0 0 0.2582 0.4988 0.6103 0.5558 0 0