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

1 visualizzazione (ultimi 30 giorni)
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
load(video_trial{i_video_trial}(1:end-2)); % load video data
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!

Risposta accettata

Rik
Rik il 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
S=load(video_trial{i_video_trial}(1:end-2)); % load video data
dlcmat=S.dlcmat;
nframes = size(dlcmat,1);
traj_y = dlcmat(:,(marker_num_plot-1)*3+2); % get trace from trial
end
  3 Commenti
Elise Mangin
Elise Mangin il 26 Apr 2023
YES! Thank you. It works now with this code.
I apologize - I am still learning. Thanks so much for the help!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by