how to detect vector value in sequence in stateflow
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi
i have large vector data, let say vector(1x200) in stateflow that the value is between 1 to 10, i want to detect at least 10 consecutive value on that vector (1x200) is bigger than 5 then the action y= 1000, for example:
vector(1x10): X = [3 4 6 6 6 6 7 2 1 3]
in that vector, vector 3 to 7 has value: bigger than 5 and 5 value (3 to 7) in sequence ,, then the condition is accepted so the value y=1000
other example: X = [3 4 6 6 6 6 4 7 1 3]
in that vector, there are vector value that bigger than 5 BUT not 5 value in sequence, cause the vector 7 value is 4,only 4 in sequence, so the condition is not accepted...
vector input value is from simulink, the question is how was the script on stateflow?? or any suggestion???
0 Kommentare
Akzeptierte Antwort
Sean de Wolski
am 9 Jun. 2011
Ahh! Nice clarification.
%Sample Data
X1=[1 1 6 6 6 7 7 2 3 4];% correct
X2=[1 1 6 6 6 7 4 2 3 4];% wrong
X3=[8 8 9 9 8 0 0 1 1 2];% condition: correct
X4=[8 8 9 9 2 8 0 1 1 2];% condition: wr
%Engine
correct = @(x)any(diff(find(diff([0 x]>5)))>=5); %is it correct?
%Checks
correct(X1)
correct(X2)
correct(X3)
correct(X4)
3 Kommentare
Fangjun Jiang
am 9 Jun. 2011
Thanks, Sean! I suspect it could be done in a way other than searching but I just couldn't come up with it. Smart!
Weitere Antworten (2)
Fangjun Jiang
am 9 Jun. 2011
This task is not that straightforward even in Matlab. I can suggest one way to do it in Matlab. Please chime in if you have other ways.
X=ceil(10*rand(1,200));
A=X>5;
B=num2str(A);
C=strfind(B,repmat('1 ',1,5)); %5 is the number of consecutive occurance
if any(C)
Y=1000
end
With this, it can be done in Stateflow but it will require using the "ml namespace operator" (see reference "Using Matlab Functions and Data in Actions"). I am not sure if you could pass those obstacles. Maybe you should re-consider your approach and use the Embedded Matlab Function block.
6 Kommentare
Siehe auch
Kategorien
Mehr zu Naming Conventions 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!