vector<double> matrix(numrows*numcols);
access via
matrix[numcols*desiredrow+desiredcol];
then you can just do a single loop to load it:
for(dx = 0; dx < numrows*numcols; dx++)
matrix[dx] = rand()%10; // approach allows simple iteration, one of many advantages to a 1-d construct).
I think your problem is that temp is not being cleared after each loop iteration, which is probably causing all sorts of problems? Also your {} notation is more confusing than usual. Whitespace costs nothing unless you are printing a physical book.