Padding arrays with zeros dynamically - Octave / Matlab -


i have add multiple arrays in loop , arrays in size need pad array x , need pad array y how can have arrays padded dynamically?

i know how pad manually (see code below) how can dynamically if size of array x or size of array y vary?

x = [1 2 3 4 5 6]' y = [3 5 7 8]';  = x + [y;zeros(2,1)];  result in = [4 7 10 12 5 6]' 

ps: i'm using octave 3.8.1 matlab

find max length , pad both of them difference.

l = max(length(x), length(y)); = [x; zeros(l-length(x),1)] + [y; zeros(l-length(y),1)]; 

it can extended more 2 vectors:

l = max(length(x), length(y), length(z)); = [x; zeros(l-length(x),1)] + [y; zeros(l-length(y),1)] + [z; zeros(l-length(z),1)]; 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -