# one matrix that is made from multiple vectors of different lengths that don't start at the same point

1 ビュー (過去 30 日間)
Kristin Scaplen 2023 年 1 月 31 日
コメント済み: Voss 2023 年 2 月 2 日
Hi Everyone,
I am using tracking software to extract behavioral features from mulitple individuals in a video and I am running into problems generating a matrix of all of the individual data from the resulting .mat file. The problem is that because of tracking issues each vector (data for each individual) is not necessarily the same size and doesn't neccessarily start at the same time. To solve this I have created a padded array:
M=zeros (15, 35,000);
M(1,1:length(data{1,1}))=data{1,1};
M(2,1:length(data{1,2}))=data{1,2};
M(3,1:length(data{1,3}))=data{1,3};
M(4,1:length(data{1,4}))=data{1,4};
M(5,1:length(data{1,5}))=data{1,5};
M(6,1:length(data{1,6}))=data{1,6};
M(7,1:length(data{1,7}))=data{1,7};
M(8,1:length(data{1,8}))=data{1,8};
M(9,1:length(data{1,9}))=data{1,9};
M(10,1:length(data{1,10}))=data{1,10};
M(11,1:length(data{1,11}))=data{1,11};
M(12,1:length(data{1,12}))=data{1,12};
M(13,1:length(data{1,13}))=data{1,13};
M(14,1:length(data{1,14}))=data{1,14};
M(15,1:length(data{1,15}))=data{1,15};
But instead of starting at cell 1 for each row, I would like to start pasting the data at the cell when the tracking started for that individual. Tracking of some individuals are not picked up until 5570 so instead of starting at 1, I'd like to start at 5570.
I tried M(10,5570:length(data{1,10}))=data{1,10};
But I get an error saying "Subscripted assignment dimension mismatch". I get the same error if I try:
I tried M(10,5570:end)=data{1,10};
Any ideas as to how to paste vectors into a matrix that start at a specific point and continue from there to the end?
Thanks!!

サインインしてコメントする。

### 採用された回答

Voss 2023 年 1 月 31 日
Assuming data{1,10} is a row vector (i.e., the cell data(1,10) contains a row vector), then the following would work:
M(10,5570:5570+length(data{1,10})-1) = data{1,10};
So you can set up your starting indices for each row, and then proceed in a loop:
M = zeros(15, 35000); % Note that zeros(15, 35,000) is an empty 3D array (of size 15-by-35-by-0)
start_idx = [1 5570 1 5570 5570 11140 1 1 5570 5570 1 1 1 5570 5570]; % start index for each row of M
for ii = 1:size(M,1)
M(ii,start_idx(ii):start_idx(ii)+length(data{1,ii})-1) = data{1,ii};
end
##### 2 件のコメント表示非表示 1 件の古いコメント
Voss 2023 年 2 月 2 日
You're welcome!

サインインしてコメントする。

### カテゴリ

Find more on Logical in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!