save array data in a loop
1 view (last 30 days)
Show older comments
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 Comment
Nirav Sharda
on 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.
Answers (0)
See Also
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!