Running a loop for certain time

I found an old post about this but it didn't really answer my question, so i will make a new one. I want to run a loop for a specific amount of time and take measurements in this loop at a specific rate. Here is the code i have so far, which does not seem to do what i want. It should run for 10 seconds doing a measurement each second. thanks

int sensePin = 0;
unsigned long starttime;
unsigned long endtime;
int i = 0;
int n;
const int sizeofv = 10;
int v[sizeofv];

void setup(){
 
 
 pinMode(sensePin, INPUT);      
 
 Serial.begin(9600);
 
  starttime = millis();
  endtime = starttime; 

while ((endtime - starttime) <= 10000) 
{
  

  i = i + 1;
  v[i] = analogRead(sensePin);
  
delay(1000);

endtime = millis();


}


void loop(){  
  
  
}

How many microseconds in 10 seconds?

A lot.

  while ((endtime - starttime) <= 10000) 
  {


    i = i + 1;
    v[i] = analogRead(sensePin);

    delay(1000);

    endtime = micros();


  }

delay delays in milliseconds. You are timing in microseconds. You are out by a factor of 1000.

Anyway, can't you just count up to 10? Why check for elapsed time anyway?

Ok yea i see i changed millis() and didnt change back... well i want to have a controlled amount of time for an observation. I had the code in matlab but i was not getting enough samples per second. so i figured i would try it here but im not good at the arduino environment.

You are putting data into the array indices v[1] to v[10] but, as array indices start from v[0], there's no v[10].
You haven't balanced your braces, so it won't compile.
i = i + 1; is the same as i++;
The endtime variable can be replaced with millis().

  for (byte i = 0; i < sizeofv; i++)
    {
    v [i] = analogRead (sensePin);
    delay(1000);
    }

That's a lot simpler, right?

Much, but how would i use that to change the sampling frequency. I want to have it more like 1000 samples/sec and maybe run for 30-60 seconds. Sorry im such a noob.

, but how would i use that to change the sampling frequency.

Not using delay.
analogRead itself takes around 100 microseconds, so that needs to be taken into account.

Have a look at blink without delay for clues