save array data in a loop

조회 수: 1 (최근 30일)
sarmad m
sarmad m 2017년 2월 14일
댓글: Nirav Sharda 2017년 2월 22일
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