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!
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!