キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 

Array processing

In the attached file, I need to detect a threshold around 0.5 in both signals then find the difference time between in all happening time in which threshold is met. In the example, two points are such as that. One of them is around the 10s and the other is around 130s. But my code detects just the last one (around 130s).

0 件の賞賛
メッセージ11/20
2,308件の閲覧回数

After looking at your code for five seconds, it is peppered with race conditions and your results are unpredictable. In the second frame, the local variables is read way before the indicator gets updated with new values, because the inner FOR loops and the case structure execute in parallel.

 

As for the task, I am sure you could do it with 5% of the current code using a single loop. Try it.

 

(Your first inner FOR loops do absolutely nothing. What is their purpose? Your second FOR loops are pretty pointless. You need to iterate n-1 times, because else you run out of elements in the last iteration. Index array is resizeable, you only need once instance. There is the "in range and coerce function", try it). Your indicators get updated as many times as the boolean turns true and only the last value is available after the loops complete. Your sequence structure serves no purpose. Why is there an outer while loop? You are spinning it as fast as the computer allowws, recalculating the same over and over, burning 100% of a CPU code yielding nothing new ever.)

0 件の賞賛
メッセージ12/20
2,303件の閲覧回数

I changed it but it does not work. You can see in the attached file.

0 件の賞賛
メッセージ13/20
2,301件の閲覧回数

Read the rest of my message above. Now you placed it inside the FOR loop, but there is sitll no way to tell if the local variable gets read before or after its indicator gets updated. Again, all you see at the end is the last update from some random calculation. Think dataflow!

 

You need to get rid of the local variables!

0 件の賞賛
メッセージ14/20
2,298件の閲覧回数

There is also a function called threshold detector which will do mcuh of what the For Loops in the 2nd frame are doing.

0 件の賞賛
メッセージ15/20
2,290件の閲覧回数

Thank you for your help. I think it works now but I am so eager to make it better. How is that now? 

 

0 件の賞賛
メッセージ16/20
2,284件の閲覧回数

A bit better.  But can still be improved based on Altenbach's comments and mine.

 

I cleaned up your code.

 

But it looks like your code can be replaced by the Threshold Detector.  Two subVI's Done!

0 件の賞賛
メッセージ17/20
2,280件の閲覧回数

Thanks. But why Threshold Detector gives index one number less than my program? My code is still wrong?

0 件の賞賛
メッセージ18/20
2,278件の閲覧回数

Also don't forget about the conditional tunnel.

0 件の賞賛
メッセージ19/20
2,267件の閲覧回数

Your code is wrong.  You started out with i=0 in the first iteration  and compared i with i-1.  When i is 0, i-1 = -1.  There is no such thing as an array index of -1. 

 

So working in the loop, you need to start at 0 and look ahead to i+1.   When true, the code is returning i.

The Threshold detector is probably set up to (can't tell, the algorithm is hidden in a dll), to give the first index that is after the crossing.

 

To make them give identical results, you can easily do a +1 on the array of indices.

0 件の賞賛
メッセージ20/20
2,252件の閲覧回数