New answers tagged

2

Where can the code be improved? First of all: Try to avoid loops (Do, For, While) where possible - they're usually much more verbose than functional alternatives. Second: Read the documentation. ComponentMeasurements can take a list of measurements, and will then return a list of values for each component. Third: Use functions to encapsulate units of ...


1

img = Import["http://i.stack.imgur.com/bkNTj.png"]; pos = ComponentMeasurements[img// Binarize, {"Centroid", "EquivalentDiskRadius"}][[All, 2, 1]]; Length[pos] Show[img, Graphics[{Red, Circle[#, 10]} & /@ pos]] 3 You might be interested in Count flowers in an image and Count Elements in Image. For your complete folder, SetDirectory[...


0

Clear[p, a, b, G, H, P, U, S, T] p[A1] = 30; p[A2] = 30; p[B1] = 60; p[B2] = 60; p[A12] = 100; p[B12] = 70; a[l1] = 10; a[h1] = 40; b[l1] = 20; b[h1] = 50; a[l2] = 10; a[h2] = 40; b[l2] = 20; b[h2] = 50; (*all low*) x = a[l1]; y = a[l2]; u = b[l1]; v = b[l2]; Rather than adding conditions to mutiple definitions, use Piecewise (*G[1,x_,y_] is ...


1

There may be reasons you elected to write: p[A1] := 30 rather than simply pA1 = 30; and I would think it would be legitimate. However I re-wrote your code using (what to me) seems a simpler format. pA1 = 30; pA2 = 30; pB1 = 60; pB2 = 60; pA12 = 100; B12 = 70; al1 = 10; ah1 = 40; bl1 = 20; bh1 = 50; al2 = 10; ah2 = 40; bl2 = 20; bh2 = 50; x = al1; y =...


5

Preamble Leonid's method is new to me and quite interesting. I expect that as with most of his methods it is well reasoned and has advantages that are not immediately apparent. Nevertheless I also find value in alternative methods, so here is one of mine. I shall use his example code so that these methods may be compared directly. Boilerplate General::...


12

Implementation This is indeed an important problem. It is usually best to have a separate function testing various options. Here is the solution I propose: a wrapper that would factor out the testing functionality from the main function. Here is the code: ClearAll[OptionCheck]; OptionCheck::invldopt = "Option `1` for function `2` received invalid value `3`"...



Top 50 recent answers are included