MATLAB: How to save all the values of the matrix

forfor loophelpmatrixmatrix arraymatrix manipulation

I need to save the output [xi ,yi, P] in a 9×3 matrix
this is the code i currently have
for v = 1:9
CN = centroids(v,:); %Which Row
x = CN(1);
y = CN(2);
[xiv,yiv,P] = impixel(rgbG,x,y); %rgbG is the image that i am getting pixel color from
end
This is is i want the output to look like
[xi1,yi1,P1]
[xi2,yi2,P2]
[xi3,yi3,P3].......
So on so forth
thank you!

Best Answer

Here is a simple adaptation of your code:
M = zeros(9,3);
for v = 1:9
CN = centroids(v,:); %Which Row
x = CN(1);
y = CN(2);
[xiv,yiv,P] = impixel(rgbG,x,y); %rgbG is the image that i am getting pixel color from
M(v,:) = [xiv, yiv, P];
end