MATLAB: How to add values to a vector instead of replacing them

for loopMATLABvector

Hey I'm trying to combine all IDs for pictures into a vector to use in a function but when I write this loop the values get replaced and i only get the value of the last i.
for i = 1:(length(p))
allIDs = [p(i) ImageIDs(1) ImageIDs(2) ImageIDs(3) ImageIDs(4)];
end
If I write "allIDs(i)" instead I get an error message saying they aren't compatible. How can I write this loop instead? Any help would be appreciated.

Best Answer

Use a row and ‘default’ column subscript for allIDs:
allIDs(i,:) = [p(i) ImageIDs(1) ImageIDs(2) ImageIDs(3) ImageIDs(4)];
That should work.