range

Matlab, matrix containing random numbers within specified range

馋奶兔 提交于 2019-11-29 12:59:54
I am absolutely new to Matlab and am trying to create an m-by-n matrix containing numbers within a specified range (ie. between -1 and 1). Is there an equivalent function to rand(m, n) where I can specify the range myself or would I need to explicitely create a bunch of random numbers (as ie. was described in this answer ) and create a matrix from them? Any pointers to relevant Documentation, etc. highly appreciated. This is straight from Matlab's documentation for rand . Is this want you want? Example 1 Generate values from the uniform distribution on the interval [a, b]: r = a + (b-a).*rand

Apply IF condition to a range Excel VBA

家住魔仙堡 提交于 2019-11-29 12:50:55
I have written this code but it doesnt seems to be working , Why? Dim oRo As String Dim nRo As String Lastro = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row oRo = "J2:O" & Lastro nRo = "Q2:V" & Lastro Range("C2:G" & Lastro).Select With Range("C2:G" & Lastro) .Range("C2:G" & Lastro).Formula = "=IF(oRo*nRo<0,ROUNDUP(oRo*1.3,-2),IF(ABS(oRo) <=ABS(nRo),nRo,ROUNDUP(oRo*1.3,-2)))" End With End Sub Your best bet for maintainability is to embrace R1C1 notation when you write formulas to Excel from VBA. I still can't read R1C1, but I use it exclusively to write formulas from VBA. Here's how: Let's say

How does the Python range function have a default parameter before the actual one?

爱⌒轻易说出口 提交于 2019-11-29 12:41:09
问题 So I'm writing a function that takes an optional list and extends it to the length specified. Rather than writing it as foo(n, list=None) I was wondering how I might emulate the behavior of Python's range function which works like: >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> range(5, 10) [5, 6, 7, 8, 9] That is, with the default parameter first. For reference trying to naively set this up returns a syntax error: def foo(x=10, y): return x + y SyntaxError: non-default argument follows

Enumerable.Range implementation

北战南征 提交于 2019-11-29 12:37:15
What is the precise implementation of Enumerable.Range in .Net; preferable .Net 4? Is it a yielded for-loop? A custom implementation (IEnumerable, IEnumerator) or? CraigTP The accepted answer on this question should give you the answer: public static class Enumerable { public static IEnumerable<int> Range(int start, int count) { var end = start + count; for(var current = start; current < end; ++current) { yield return current; } } } This isn't the exact code, as there is a lot of error checking etc. going on within the Range method, and internally, it calls other methods, however, the quoted

Find a string in a document and delete everything after it

岁酱吖の 提交于 2019-11-29 12:24:21
I want to find a string in a word document and delete everything after it. What is the best way to do this without using the Selection object? Use a Range object instead. Straight outta the Word 2003 help: If you've gotten to the Find object from the Range object, the selection isn't changed when text matching the find criteria is found, but the Range object is redefined. The following example locates the first occurrence of the word "blue" in the active document. If "blue" is found in the document, myRange is redefined Set myRange = ActiveDocument.Content myRange.Find.Execute FindText:="blue"

Subscript out of range error in this Excel VBA script

╄→尐↘猪︶ㄣ 提交于 2019-11-29 12:23:09
I would like to copy data from a CSV file into an Excel worksheet. There are 11 .csv files. So far I have this (it is a modified version from a previous post): Sub importData() Dim filenum(0 To 10) As Long filenum(0) = 052 filenum(1) = 060 filenum(2) = 064 filenum(3) = 068 filenum(4) = 070 filenum(5) = 072 filenum(6) = 074 filenum(7) = 076 filenum(8) = 178 filenum(9) = 180 filenum(10) = 182 Dim sh1 As Worksheet On Error GoTo my_handler For lngPosition = LBound(filenum) To UBound(filenum) 'Windows(filenum(lngPosition) & ".csv").Activate Workbooks.Add(filenum(lngPosition) & ".csv").Activate

Numerical range iterators in boost?

走远了吗. 提交于 2019-11-29 12:15:45
问题 I'm aware of the range iterators in boost, and as for this reference, it seems there should be an easy way of doing what I want, but it's not obvious to me. Say I want to represent a numerical range, 0 to 100 (inclusive or not), say range(0,100) . I would like to do something like: for_each(range<int>(0,100).begin(), range<int>(0,100).end(), do_something); where do_something is a functor. This iterators shouldn't have the overhead of having an underneath vector or something like this, but to

Equivalent to exclusion constraint composed of integer and range

淺唱寂寞╮ 提交于 2019-11-29 12:07:39
I need to have something equivalent to this exclusion constraint drop table if exists t; create table t ( i int, tsr tstzrange, exclude using gist (i with =, tsr with &&) ); ERROR: data type integer has no default operator class for access method "gist" HINT: You must specify an operator class for the index or define a default operator class for the data type. I guess the problem is obvious from the error message. How to do it? Erwin Brandstetter You need to install the additional module btree_gist to make it work. The module installs the missing operator class. Details in this related answer:

Subset by multiple ranges [duplicate]

筅森魡賤 提交于 2019-11-29 11:38:00
This question already has an answer here: Efficient way to filter one data frame by ranges in another 3 answers I want to get a list of values that fall in between multiple ranges. library(data.table) values <- data.table(value = c(1:100)) range <- data.table(start = c(6, 29, 87), end = c(10, 35, 92)) I need the results to include only the values that fall in between those ranges: results <- c(6, 7, 8, 9, 10, 29, 30, 31, 32, 33, 34, 35, 87, 88, 89, 90, 91, 92) I am currently doing this with a for loop, results <- data.table(NULL) for (i in 1:NROW(range){ results <- rbind(results, data.table

How to compare 2 lists of ranges in bash?

末鹿安然 提交于 2019-11-29 11:33:21
Using bash script (Ubuntu 16.04), I'm trying to compare 2 lists of ranges: does any number in any of the ranges in file1 coincide with any number in any of the ranges in file2? If so, print the row in the second file. Here I have each range as 2 tab-delimited columns (in file1, row 1 represents the range 1-4, i.e. 1, 2, 3, 4). The real files are quite big. file1: 1 4 5 7 8 11 12 15 file2: 3 4 8 13 20 24 Desired output: 3 4 8 13 My best attempt has been: awk 'NR=FNR { x[$1] = $1+0; y[$2] = $2+0; next}; {for (i in x) {if (x[i] > $1+0); then {for (i in y) {if (y[i] <$2+0); then {print $1, $2}}}}}