Working with structures, I cannot make an "if" work inside a "for" loop and cannot make "find peaks" work either; Any suggestions?

조회 수: 2 (최근 30일)
I am trying to work on vectors inside the structure (arrays), but when I have an if statement inside the for loop, it doesn't do what I am expecting it to. This is to remove the unwanted (pen-up) data in a drawing task, i.e., the threshold is 0.1.
Plus, I need to extract the corners of a drawing task data. i.e., we have asked subjects to draw some patterns for us like cubes and now I have to detect the corners of each drawing in order to compare it to the original pattern that we have (although the pattern is so big and I have problems matching them with the drawings) and analyse the tremor when drawing. What I was doing was plotting the graphs for each vector (I have x and y coordinates) to get the whole drawing and then I wanted to compare it to the original template using imshowpair (do we have any other ways of doing it that seems more reasonable to you?). But findpeak does not work either as I just need the corners that act as local maximums (I used the threshold to get only 4 maximums for cubes, etc.). I understand the code for this part is incomplete and I get errors, too (Attempted to access x(188); index out of bounds because numel(x)=13.); I just stopped as it was not doing what I wanted.
I have the simple code:
files = dir('.../controls/*.txt');
for k = 1:length(files)
data{k} = load(fullfile('.../controls/', files(k).name), '-ascii');
if data{k}(:,6) < 0.1
data{k}(:,6) = 0;
end
data{k}(:,2) = data{k}(:,2) * 20.32;
data{k}(:,3) = data{k}(:,3) * 15.24;
% Rescaling the drawings to match the
% dimensions of the active area of
% the tablet, which were 20.32 x 15.24 cm
plot(data{1,k}(:,2));
[pksx{k},locsx{k}] = findpeaks(data{1,k}(:,2),'MinPeakHeight',11);
plot(data{1,k},data{1,k}(:,2),data{1,k}(locsx{k}),pksx{k},'or')
plot(data{1,k}(:,3));
[pksy{k},locsy{k}] = findpeaks(data{1,k}(:,3),'MinPeakHeight',11);
plot(data{1,k},data{1,k}(:,3),data{1,k}(locsy{k}),pksy{k},'og')
end
  댓글 수: 2
dpb
dpb 2015년 7월 20일
Think you'll need to supply some data and perhaps figures to illustrate what you're expecting to do here...nobody can do anything with your code as is.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2015년 7월 20일
Are you sure about
if data{k}(:,6) < 0.1
data{k}(:,6) = 0;
end
That tests to see if all entries in column 6 are less than 0.1, and if so sets them all to 0, but if even one is judged to not be strictly less than 0.1, none of them are set to 0.
Perhaps you want
idx = data{k}(:,6) < 0.1;
data{k}(idx,6) = 0;
  댓글 수: 9
Walter Roberson
Walter Roberson 2015년 7월 21일
Sorry, nothing is obvious to me. I would need the toolbox to test with.
Amir Dehsarvi
Amir Dehsarvi 2015년 7월 21일
Thank you very much for helping anyway...please let me know if you had any other suggestions about this.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by