Tag Info

New answers tagged

1

You can inject the values of the iterator variable into held expressions using With as suggested in the comments. Alternatively, you can use ButtonBar[Table[Row[ToString /@ #, " of "] :> Print[#] &[i], {i, myHand}]] or ButtonBar[Table[Row[ToString /@ j, " of "] :> Print[j] /. j -> i, {i, myHand}]] You can also create the list of buttons ...


1

You are right. It is trivial. Table["This number = " <> ToString @ k, {k, 3}] {"This number = 1", "This number = 2", "This number = 3"}


4

DateString can be a slowpoke without an explicit output element specification. Also, you can apply it to your list of dates before you put them through your evaluation. Finally, you could also replace your Table expressions (and that Position/Extract usage) with Map and MapThread, along with some other small optimizations: Here's an example modification run ...


2

There are likely many ways to go about this, but here is one which uses pattens and replacement rules: data = {{-0.6, 0.04, 22}, {0.1, 0.3, 1}, {0.4, 0.05,0.01}}; rule = {a_, b_, c_} /; Abs[a] > 0.5 && Abs[b] <= 0.05 :> {Item[Style[a, Red, Bold], Background -> LightBlue, FrameStyle -> Darker[Red, 0.25], Frame -> ...


1

You can do something like: TableForm[ Map[If[Abs[#[[1]]] > 0.5 && #[[2]] <= 0.05, {Item[#[[1]], Background -> LightBlue], Item[#[[2]], Background -> LightBlue], #[[3]]}, #] &, M], TableHeadings -> {{"x", "y", "z"}, {"correlation", "pValue", "tStatistic"}}] Grid has, as Kuba noted, a direct way of doing this, check ...


3

This is a job for Transpose. table = Take[Import["~/myfile.csv"]]; {x, y, z, time, bool} = Transpose[table]; (* do stuff *) output = Transpose[{x, y, z, time, bool}]; Export["newfile.csv", output, "CSV"]


3

What's wrong with nonPrimeSequence[x_] := NestWhileList[# + 1 &, x, Not[PrimeQ[# + 1]] &] nonPrimeSequence[24] (* {24, 25, 26, 27, 28} *) Well?


2

Here is another approach using only the functionality of TableForm itself: list = Range[4] & /@ Range[4]; title = "Bravo"; TableForm[{{list}}, TableHeadings -> {None, {title}}] This nests the list deep enough inside {{ }} so that the column labels provided by TableHeadings are applied only to a single column containing the actual table. The ...


4

Labeled[TableForm[list], title, Top]


3

There are many alternatives to If in Mathematica. One that you might use is rule replacement: Table[Mod[k, 2] /. {0 -> k, _ -> Sequence[]}, {k, 0, 10}] {0, 2, 4, 6, 8, 10} Another is that you might write your own function that does exactly what you want, because Mathematica's Hold-related attributes allow you to write many control structures as ...


4

For variety's sake (and because I like Sow and Reap)... Reap[Do[If[Mod[k, 2] == 0, Sow[k]], {k, 0, 10}]][[2, 1]]


5

You can do this :- Table[If[Mod[k, 2] == 0, k, ## &[]], {k, 0, 10}] {0, 2, 4, 6, 8, 10}


1

dr = {4, 7, 4, 8, 8, 5, 3, 4, 5, 4, 5, 5}; val = 4; Flatten@Position[Thread[Less[dr, val]], True] {7}


2

I think this does what you're trying to accomplish. Note, you're not using "pure functions" anywhere in your code, I just jiggered it to get what I think you're after, there are almost certainly cleaner ways to do what I think you're trying to do (like actually using pure functions, etc.) tempMakeTableAn[{analEqs_, concs_, initConcs_, rateConstants_, ...


2

You are seeing Module work exactly as it should, because it is designed to implement lexical scoping. Take it away, Wikipedia: In lexical scoping (or lexical scope; also called static scoping or static scope), if a variable name's scope is a certain function, then its scope is the program text of the function definition: within that text, the variable ...


3

Here's a way using ListConvolve and SparseArray's properties: list = {1, 2, 5, 2, 9}; SparseArray[UnitStep@ListConvolve[{-1, 1}, list]]["NonzeroPositions"] (* {{3}} *)


3

pckpstn = Pick[Range[Length[#] - 1], Negative@Differences@#] &; lst = {3, 1, 2, 5, 2, 1, 9, 1}; pckpstn@lst (* {1, 4, 5, 7} *)


5

Here's a way: lis = {1, 2, 5, 2, 9}; Flatten[Position[Greater @@@ Partition[lis, 2, 1], True]] (* {3} *) Here's an explanation: Partition will group the elements in twos Partition[lis, 2, 1] (* {{1, 2}, {2, 5}, {5, 2}, {2, 9}} *) Then we use @@@ to apply a Greater at level 1 Greater @@@ Partition[lis, 2, 1] (* {False, False, True, False} *) Since 5 ...


3

HanningFilter[signal_List] := With[{len = Length[signal]}, 2 signal Sin[Pi Range[len]/len]^2] Sin, Times,Power are Listable,that means Attributes /@ {Sin, Times, Power} Sin[{a, b}] {a, b}^2 {a, b} {c, d} (*{{Listable,NumericFunction,Protected},{Flat,Listable, NumericFunction,OneIdentity,Orderless,Protected}, {Listable, NumericFunction, ...



Top 50 recent answers are included