for-loop

How to update counter variable in a for loop

笑着哭i 提交于 2020-06-21 05:33:10
问题 Say I have a for loop that counts from 10 down to 1 with counter k . In the loop, when k becomes 5, I make k=4 . When I output k in each loop, I expected it would skip the 4 like so: 10 9 8 7 6 5 3 2 1 Instead I got all the numbers from 10 down to 1, it did not skip the 4. How can I make it so that it skips 4? for k=10:-1:1 if i==5 k=i-1; end end 回答1: You cannot modify the loop index from within the loop in MATLAB. Your two options are to omit that that index value prior to the loop numbers =

For loop in R that calculates for the group and then the components

笑着哭i 提交于 2020-06-18 05:31:27
问题 I have a set of data and a loop containing numerous calculations for the data set, where the individual components of the set are split into a subset and cycled through one by one. However I need to be able to execute the same calculations across the original data set as a whole first. For a fictional data set called masterdata with 3 components (column D1) and numerous variables (X2-X10) as such: # masterdata # D1 X2 X3 X4 X5 X6 X7 X8 X9 X10 # A NA NA NA NA NA NA NA NA NA # B NA NA NA NA NA

Delete rows based on values within cell, optimising

天涯浪子 提交于 2020-06-17 11:05:33
问题 I have script running on a weekly bases deleting rows from a document and then pasting these values to another sheet for data analysis, however as the document grows (+20,0000 rows) my script times out. Anyway on how to optimise the script to perhaps use less processing/memory and run faster? var rowsDeleted = 0; for (var i = 0; i <= numRows - 1; i++) { var row = values[i]; if (row[0] == 'delete' || row[0] == '') { data.deleteRow((parseInt(i)+1) - rowsDeleted); rowsDeleted++; } } 回答1: In your

How to use _for_ in the dataframes in R programming

时光怂恿深爱的人放手 提交于 2020-06-17 09:49:28
问题 I'm trying to fit several models in R using the for loop. The data I want to fit is the classical Auto data in a R pre-build package. Let's discover the names of the columns of this dataframe: names(Auto) "mpg" "cylinders" "displacement" "horsepower" "weight" "acceleration" "year" "origin" "name" I want to fit the all these predictors one by one with the target 'mpg'. Instead of doing: autotest1 = lm(mpg~cylinders, data=Auto) autotest2 = lm(mpg~displacement, data=Auto) autotest3 = lm(mpg

How does for-loop actually work in python

冷暖自知 提交于 2020-06-17 09:43:07
问题 I used to thought that for-loop in python work like this it first makes an iterator by doing iter(iterable) then does next(that_new_iterator_object) and when it raises StopIteration then for-loop ends and goes to else block (if provided) but here it is working differently >>> a = [1,2,3,4,5,6,7,8,9] >>> for i in a: del a[-1] print(i) 1 2 3 4 5 where are the other numbers 6,7,8,9 the new iterator object that for-loop creates and variable a is different 回答1: The for loop works just as you

How can I handle an array where elements contain spaces in Bash?

半腔热情 提交于 2020-06-17 08:06:44
问题 Let's say I have a file named tmp.out that contains the following: c:\My files\testing\more files\stuff\test.exe c:\testing\files here\less files\less stuff\mytest.exe I want to put the contents of that file into an array and I do it like so: ARRAY=( `cat tmp.out` ) I then run this through a for loop like so for i in ${ARRAY[@]};do echo ${i}; done But the output ends up like this: c:\My files\testing\more files\stuff\test.sas c:\testing\files here\less files\less stuff\mytest.sas and I want

How do I make a 'for' loop in the command prompt?

浪子不回头ぞ 提交于 2020-06-16 05:56:29
问题 I'm working with a command-line program that does image-processing, and I need to run the same command on an entire folder of images. I have heard that I can run loops in the command prompt, but I have seen all sorts of different examples online and can't figure out the syntax. The images in the folder are labled "single0.pgm, single1.pgm, single2.pgm,..." all the way to single39.pgm. The command I need to run is: DebayerGPU.exe -demosaic DFPD_R -CPU -pattern GRBG -i single0.pgm -o single0

How do I make a 'for' loop in the command prompt?

泪湿孤枕 提交于 2020-06-16 05:56:09
问题 I'm working with a command-line program that does image-processing, and I need to run the same command on an entire folder of images. I have heard that I can run loops in the command prompt, but I have seen all sorts of different examples online and can't figure out the syntax. The images in the folder are labled "single0.pgm, single1.pgm, single2.pgm,..." all the way to single39.pgm. The command I need to run is: DebayerGPU.exe -demosaic DFPD_R -CPU -pattern GRBG -i single0.pgm -o single0

How can I construct a matrix given a generator for this cyclic group?

倾然丶 夕夏残阳落幕 提交于 2020-06-16 04:12:46
问题 Let F[q^p] be a finite cyclic set of polynomials, where q is a prime number and p is an integer greater than 0. Each element in F[q^p] will be a polynomial up to degree (p-1) under (mod q). Ex: F[2^2]={0,1,x,1+x} Ex: F[3^4]={0,1,2,0+x,1+x,2+x,0+x^2,1+x^2,2+x^2,x+x^2,1+x+x^2,2+x+x^2,2x+x^2,1+2x+x^2,2+2x+x^2,0+2x^2,1+2x^2,2+2x^2,x+2x^2,1+x+2x^2,2+x+2x^2,2x+2x^2,1+2x+2x^2,2+2x+2x^2,...,2+2x+2x^2+2x^3} Thus, there will be q^p elements in F[q,p]. Assume that we have a generator theta, where theta

How to make several for loops to perform different functions using R

*爱你&永不变心* 提交于 2020-06-13 11:45:11
问题 This is my limit point and I need R professionals to help me with a quick way of looping my codes. I have a df like: GENES <- c('RCD-7','ADF-1','BBF-10','BBF-10','BBF-10','CCF-103') pos_1 <- c ('T','G','T','A','C','T') pos_2 <- c ('G','T','A','A','C','G') df <- data.frame(GENES,pos_1,pos_2) print(df) GENES pos_1 pos_2 RCD-7 T G ADF-1 G T BBF-10 T A BBF-10 A A BBF-10 C C CCF-103 T G What I do with the df is that I want to calculate the percentage of each Nucleotide (let's say alphabet) in each