Re: Algorithmic issue

Posted by Olivier Burri on
URL: http://imagej.273.s1.nabble.com/Algorithmic-issue-tp5016298p5016300.html

Dear Philippe,

I am unsure on what you mean by 'if loop', there is only one loop in your code, the 'for' loop.

As far as I use, Matlab is capable of doing something like that where accessing a vector's indexes with a Boolean vector allows you to only work on the 'true' elements.
----- Matlab example:
k = round(rand(10,1)*10);
disp(k(k>5))
example output of the last command:
    10
    10
     8
     9
     8
    10
----- Matlab example ends

In the macro language, you need to loop (with the 'for') and check if a given condition is met (with the 'if') as you did in your example. There is no shorthand notation either, unfortunately.

All the best,

Oli

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Philippe CARL
Sent: lundi, 2 mai 2016 18:40
To: [hidden email]
Subject: Algorithmic issue

Dear all,

I would have a question that is not specifically ImageJ related, but rather with programming in general.

Indeed, please consider the following macro code:

                boola = newArray(true, false, true, true, false);

                for(i = 0; i != boola.length; i++)

                               if(boola[i])

                                               print(boola[i]);

Would there be a way to combine the for and if loops within a single one giving the same result than higher?

I thank you very much in advance about your lighting concerning this question.

My best regards,

Philippe

 

Philippe CARL

Laboratoire de Biophotonique et Pharmacologie

UMR 7213 CNRS - Université de Strasbourg

Faculté de Pharmacie

74 route du Rhin

67401 ILLKIRCH

Tel : +33(0)3 68 85 41 84


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html