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.
Amir Dehsarvi
Amir Dehsarvi 2015 年 7 月 20 日
I have now attached one of my data files.

サインインしてコメントする。

採用された回答

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 Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by