save array data in a loop
1 回表示 (過去 30 日間)
古いコメントを表示
Hi
in the following code I'm searching for a match of indexes between 2 files , if I found a match take -6,6 elements from the 1st file .
I need to save the found data as (1,13) . data array shows the elements but I can't save them because saves one over the other
earFilename = 'EAR_v1.txt';
stateFilename = 'output_close_tags_video_1.txt';
% read EAR values
earfile = fopen(earFilename,'r');
formatSpec = '%d %f %f';
sizeA = [3 Inf];
earVector = fscanf(earfile, formatSpec, sizeA);
earVector = earVector';
% read state file
statefile = fopen(stateFilename,'r');
formatSpec = '%d %*s';
sizeA = [1 Inf];
stateVector = fscanf(statefile, formatSpec,sizeA);
stateVector = stateVector';
% create a dataset containing framenumber, EAR, state
dataset = [earVector, -1*ones(size(earVector,1),1)];
% for each positive state, +-6 frame are marked as positive
data=[];
for i = stateVector'
rowNumber = find(dataset==i);
for j = -6:6
data=(rowNumber+j);
disp(data)
1 件のコメント
Nirav Sharda
2017 年 2 月 22 日
You can try to append the result to the data vector by using data = [data; rowNumber+j] instead of data=(rowNumber+j). Also if you know the size of data in advance you can pre-allocate and use that instead as that is much faster. I hope this helps.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!