how to use for loop to compute a matrix

1 Ansicht (letzte 30 Tage)
Kong
Kong am 5 Mai 2020
Kommentiert: Sindar am 6 Mai 2020
Hello. I'm a beginner at Matlab.
I want to use for loop.
I got data (25 x 12852) using this code.
I want to concatenate the matrix (dist).
For example, the last part of whole code,
dist = dtw(data(:,1),data(:,2));
dist = dtw(data(:,2),data(:,3));
dist = dtw(data(:,3),data(:,4));
dist = dtw(data(:,4),data(:,5));
dist = dtw(data(:,5),data(:,6));
......
dist = dtw(data(:,12851),data(:,12852));
Finally, I want to get one matrix.
Can I get an idea to solve this?
Also, is it resonalble to use dynamic time warping (DTW) for video classification?
clear all
close all
%// read the video:
list = dir('*.avi')
% loop through the filenames in the list
for k = 1:length(list)
reader = VideoReader(list(k).name);
vid = {};
while hasFrame(reader)
vid{end+1} = readFrame(reader);
end
%// estimate foreground as deviation from estimated background:
cellSize = [8 8];
for i=1:25
fIdx(i) = i; %// do it for frame 1 ~ 60
frameGray{i} = vid{fIdx(i)};
[featureVector{i},hogVisualization{i}] = extractHOGFeatures(frameGray{i},'CellSize',cellSize);
end
data = cell2mat(featureVector');
data = double(data);
dist = dtw(data(:,5),data(:,6));
end

Akzeptierte Antwort

Sindar
Sindar am 6 Mai 2020
Bearbeitet: Sindar am 6 Mai 2020
Assuming each one produces a 25 x 12852 dist array, you can do this fairly easily. Which dimension do you want to concatenate on?
This solution adds each one as a new "page" (3rd dimension)
clear all
close all
%// read the video:
list = dir('*.avi')
% preallocate dist
dist = zeros(25,12852,length(list));
% loop through the filenames in the list
for k = 1:length(list)
...
dist(:,:,k) = dtw(data(:,5),data(:,6));
end
If you want to concatenate on rows:
dist = zeros(25*length(list),12852);
...
dist((1:25)+25*(k-1),:) = dtw(data(:,5),data(:,6));
or columns:
dist = zeros(25,12852*length(list));
...
dist(:,(1:12852)+12852*(k-1)) = dtw(data(:,5),data(:,6));
  1 Kommentar
Sindar
Sindar am 6 Mai 2020
Looking back at your code, it seems dist might be a different size, and you may want a second loop over the size of data. Hopefully my answer still helps

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by