I have a matrix 2×20 from a text file
I want to add a row of ones to that matrix
twopts = reshape(textread('input.txt', '%s'),2,20); % 2 by 20
ones_row = ones(1,20); %1 by 20 of ones
twopts = [twopts;ones_row]
Gives me an error:
“Error using vertcat CAT arguments dimensions are not consistent.”
But the matrix dimensions match… 2×20 and 1×20 to make 3×20
What’s wrong with it and how do I fix it?
twoptsis a cell array of strings andones_rowis a matrix, you can’t put these together.Does this do what you want?
Alternatively, if the input data contains numbers, not text, you might want to convert the cell array to a matrix instead: