Combing 2 arrays of different size in matlab
1 view (last 30 days)
Show older comments
Viral Solanki
on 23 Jun 2015
Answered: Steven Lord
on 23 Jun 2015
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?
0 Comments
Accepted Answer
Azzi Abdelmalek
on 23 Jun 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)]
0 Comments
More Answers (1)
Steven Lord
on 23 Jun 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.
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!