# How can i make a dinamic row in a matrix or a cell?

1 view (last 30 days)
Cholo Aranda on 27 Nov 2021
Edited: Cholo Aranda on 28 Nov 2021
I have a slight problem concatenating a row from a certain array let's say:
%Normal Array
arr = [1,2,3;4,5,6];
%i want to encrease one row specific like this:
arr(1,:) = [arr(1,:), 7];
%I want this result:
arr => [1,2,3,7;4,5,6];
% but i still have this kind of error: "Error Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-2."
% ¿how can i solve this please? I also tried with cells but i have the same error:
c = {1,2,3};
c = {c;{3,2,4,5}};
c(1,:) = {c,{4}};

the cyclist on 27 Nov 2021
Edited: the cyclist on 27 Nov 2021
In MATLAB, there cannot be an "empty" spot in a numerical array. So, you need to decide what you want in that spot. Sometimes a zero or a NaN can be a placeholder. So, you could do
arr = [1,2,3;4,5,6];
arr = [arr [7;NaN]]
arr = 2×4
1 2 3 7 4 5 6 NaN
Similarly, a cell array could have an empty array in one location
C = num2cell([1,2,3;4,5,6])
C = 2×3 cell array
{[1]} {[2]} {[3]} {[4]} {[5]} {[6]}
C = [C,{7;[]}]
C = 2×4 cell array
{[1]} {[2]} {[3]} {[ 7]} {[4]} {[5]} {[6]} {0×0 double}
Cholo Aranda on 28 Nov 2021
thank you very much :)

R2021a

### Community Treasure Hunt

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

Start Hunting!