save array data in a loop

1 次查看(过去 30 天)
sarmad m
sarmad m 2017-2-14
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
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 CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by