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

Azzi Abdelmalek
Azzi Abdelmalek el 23 de Jun. de 2015
oldarr = [1,2,3,4,5,6,7,8]
newarr = [1,2,3,4,5,6,7,8,9,10]
n=numel(oldarr)
m=numel(newarr)
nm=max(n,m)
combinearr = [oldarr nan(1,nm-n); newarr nan(1,nm-m)]

Más respuestas (1)

Steven Lord
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 documentation page for NaN includes this note:
"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

Etiquetas

Preguntada:

el 23 de Jun. de 2015

Respondida:

el 23 de Jun. de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by