Combing 2 arrays of different size in matlab
Mostrar comentarios más antiguos
Hello,
I have a weird problem and I can not figure out how to go about it.
I have a double array that's 1x8
I need to add another row to this array that's 1x10 and since the old array didn't have values for column 9 and 10, I want that to be NaN
so,
oldarr = [1,2,3,4,5,6,7,8]
newarr = [1,2,3,4,5,6,7,8,9,10]
combinearr =
1 2 3 4 5 6 7 8 NaN NaN
1 2 3 4 5 6 7 8 9 10
How would I do this?
Respuesta aceptada
Más respuestas (1)
Steven Lord
el 23 de Jun. de 2015
x = 1:7;
Lx = size(x, 2);
y = 1:5;
Ly = size(y, 2);
M1 = [x, NaN(1, Ly-Lx); ...
y, NaN(1, Lx-Ly)]
M2 = [y, NaN(1, Lx-Ly); ...
x, NaN(1, Ly-Lx)]
"The size inputs sz1,...,szN, as well as the elements of the size vector sz, should be nonnegative integers. Negative integers are treated as 0."
ZEROS, ONES, RAND, etc. behave the same way in case you want different padding.
Categorías
Más información sobre NaNs en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!