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

조회 수: 3 (최근 30일)
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!

채택된 답변

Rik
Rik 2023년 4월 26일
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
Elise Mangin
Elise Mangin 2023년 4월 26일
YES! Thank you. It works now with this code.
I apologize - I am still learning. Thanks so much for the help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by