# How to create a column vector corresponding to number of rows of matrices using for loop?

12 views (last 30 days)
Elise Mangin on 26 Apr 2023
Commented: Elise Mangin on 26 Apr 2023
Hi everyone,
I am trying to analyze data corresponding to animal behavioral trials. I have a bunch of x by 15 matrices (each represents 1 trial's data; x represents video frames and ranges from 1200 to 3000, but always 15 columns).
I am trying to use a for loop to create a column vector for each of the trials that contains the number of rows for that trial's data. Let's call it nframes. So for example if the trial has 1500 frames, the nframes value for that trial would show up as a column vector with 1500 rows numbered 1 through 1500.
Code thus far (removing unnecessary parts):
for i_trial = i_probe_trials' % for all trials of interest
nframes = ???
traj_y = dlcmat(:,(marker_num_plot-1)*3+2); % get trace from trial
end
What is the easiest way to do this? I've tried a number of things and I'm stuck.
Thank you!

Rik on 26 Apr 2023
You should always load to a variable. Then it is a lot easier to see where your variables come from. For this case I expect you need to use the size function. (I had to guess the variable name and this loop is overwriting the results)
for i_trial = i_probe_trials' % for all trials of interest
dlcmat=S.dlcmat;
nframes = size(dlcmat,1);
traj_y = dlcmat(:,(marker_num_plot-1)*3+2); % get trace from trial
end
Elise Mangin on 26 Apr 2023
YES! Thank you. It works now with this code.
I apologize - I am still learning. Thanks so much for the help!

### Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

R2020a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!