03-16-2016 02:24 PM
This is very dangerous code, because there is a finite possibility that the inner while loop will never stop, locking up the program forever.
It also seems overly complicated.
03-16-2016 02:27 PM
Are you right. This is ture, sometimes, when the signal is quite complex, the code does not stop. Please, do you have any suggestions? In wich way I could improve this cose? Many thanks, binfi
03-16-2016 02:47 PM - edited 03-16-2016 02:47 PM
@binfi wrote:Are you right. This is ture, sometimes, when the signal is quite complex, the code does not stop. Please, do you have any suggestions? In wich way I could improve this cose? Many thanks, binfi
I think all you need is a single FOR loo. Here's what I would do. (Of course you need to decide what to return if the condition is never met, for example, so modify as needed).
(Left to right: reshape array, FOR loop, multiply, array subset, greater, search array, index array)
03-16-2016 03:22 PM - edited 03-16-2016 03:25 PM
@altenbach thx for mentioning it, if for any subarray the i and (i+1) differs less than 10*i, the while will not exit
or did you mean something else?
03-16-2016 03:33 PM - edited 03-16-2016 03:37 PM
@jwscs wrote:@altenbach thx for mentioning it, if for any subarray the i and (i+1) differs less than 10*i, the while will not exit
or did you mean something else?
Yes, just run your code a couple of times. on occasion it will continue forever!
(Yes, if the condition is never met and we run out of elements while processing a row, index array will return two zeroes forever, never meeting the > condition. If you would change the condition to "greater or equal" it will return zero like my code when it runs out of elements and no match has been found because we get a 0=0-->TRUE.)
Still, my code is probably simpler. 😄
03-16-2016 03:37 PM
thats what i get, for acting without thinking, and posting pictures 😉
thx for the new icons i have never used. all in all i got some more knowledge out of it
:cheers:
03-16-2016 04:04 PM - edited 03-16-2016 04:05 PM
It might be cheapest (especially with huge arrays) to avoid "reshape" and "array subset" and just operate on the unmodified array. For the inner loop, use a conditional FOR loop.
This code gives about the same result and does all operations on scalars, limiting memory use.
03-17-2016 05:32 AM
Many thanks to both!! now it is working in perfect way!! you are genius...it was a pleasure for me having your suggestions!! Thanks