save array data in a loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Nirav Sharda
am 22 Feb. 2017
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.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!