As you noted, your t and image arrays are 1 x W, whereas your temp array is W x H. When you try to index
you are trying to index a 1 x W array (image) into a W x 1 array (a column of temp).
If you would like your final array dimensions to be H x W, you can use repmat as follows:
t = 1:W;
image = (255*square(t.*2.*pi/P));
temp = repmat(image, H, 1);
Is this what you're looking for?