for-loop

Bash Shell: for loop returns different values

☆樱花仙子☆ 提交于 2020-01-15 03:26:16
问题 $values contains a string which I grep from a config file. This string can be eiter: ?, ! or just a string containing words like "foo bar". values="?" for value in ${values} do echo "value is ${value}" done If I execute the script on local host, the result is: value is ? However, if i execute the script from a remote host (using ssh and sudo su - someuser "/tmp/foo.sh"), the result is: value is 2 Until now, I was not able to find out whats different. Could anyone help please? 回答1: You need to

Stripping Column or Row to Make 1D Array

放肆的年华 提交于 2020-01-15 03:21:06
问题 I want to create a 1D array from a 2D array without looping using only 1 line of code such as: newvec = oldvec(:,3) which in MATLAB would create a 1D array "newvec" from the 3rd column of "oldvec". My searching tells me the only way to do this in VBA is looping. For example: redim newvec(ubound(oldvec,1)) for i = 1 to ubound(oldvec,1) newvec(i) = oldvec(i,3) next i Is there a built in construct for stripping our entire singular dimensions of an existing 2D array to build a new 1D array? 回答1:

Assign file names to a variable in shell

给你一囗甜甜゛ 提交于 2020-01-14 22:54:23
问题 I'm trying to write a script that does something a bit more sophisticated than what I'm going to show you, but I know that the problem is in this part. I want each name of a list of files in a directory to be assigned to a variable (the same variable, one at a time) through a for loop, then do something inside of the loop with this, see what mean: for thing in $(ls $1); do file $thing; done Edit: let's say this scrypt is called Scrypt and I have a folder named Folder, and it has 3 files

Method for calculating distance between all points in a dataframe containing a list of xy coordinates

最后都变了- 提交于 2020-01-14 10:33:24
问题 I'm sure this has been answered before, but I can't find the thread for the life of me! I am trying to use r to produce a list of all the distances between pairs of xy coordinates in a dataframe. The data is stored something like this: ID = c('1','2','3','4','5','6','7') x = c(1,2,4,5,1,3,1) y = c(3,5,6,3,1,5,1) df= data.frame(ID,x,y) At the moment I can calculate the distance between two points using: length = sqrt((x1 - x2)^2+(y1 - y2)^2). However, I am uncertain as to where to go next.

Method for calculating distance between all points in a dataframe containing a list of xy coordinates

会有一股神秘感。 提交于 2020-01-14 10:32:30
问题 I'm sure this has been answered before, but I can't find the thread for the life of me! I am trying to use r to produce a list of all the distances between pairs of xy coordinates in a dataframe. The data is stored something like this: ID = c('1','2','3','4','5','6','7') x = c(1,2,4,5,1,3,1) y = c(3,5,6,3,1,5,1) df= data.frame(ID,x,y) At the moment I can calculate the distance between two points using: length = sqrt((x1 - x2)^2+(y1 - y2)^2). However, I am uncertain as to where to go next.

Run correlation between unequal sized blocks of data in 2 time series

眉间皱痕 提交于 2020-01-14 05:32:06
问题 I have two datasets and I need to estimate correlation of the series in these two datasets. For example, one series in of length 189 and the other series is of length 192. The end point of these series respond to the same time period ,i.e., Dec 2015. The difference is in the start point of this series. I need to estimate the correlation for the blocks of 12 data points in both the series starting from the last point. For ex, the first block would be from Jan 2015 to Dec 2015, second block

Asterisk Pyramid in C [closed]

只谈情不闲聊 提交于 2020-01-14 05:31:08
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 17 hours ago . Exercise: make a program that reads a natural number n and draws a pyramid of asterisks. Model for n = 5 : * *** ***** ******* ********* Code: int main () { int n, i, j=1, aux1, aux2; int spaces=1; scanf ("%d", &n); for (i=0; i<n; i++) { spaces += 1; } printf ("\n"); for (i=0; i<n; i++) { aux1 = j

how to use one query for two loops

て烟熏妆下的殇ゞ 提交于 2020-01-14 04:13:09
问题 how can i write query in this situation: this is the query $gdQuery = $conn->query("blah blah "); i want to use the above query for while loop that is two time. is to retrive skillname (name) is to retrivestudent name (student_fname) is it a correct approach if not how can i do that..? <table> <thead> <th>Paricipant</th> <?php while($gdData = $gdQuery->fetch_assoc()) { ?> <th class="text-center"><?php echo $gdData['name']; ?></th> <?php } ?> <th>Score</th> </thead> <tbody> <tr> <?php while(

gnuplot bashshell to plot several curves in one window

纵饮孤独 提交于 2020-01-14 04:09:46
问题 I need to plot a couple of curves in a single window. Using for loop in bash shell I've been able to plot them on separate files , but no success in sketching them on a single pic. I would appreciate it if you can guide me on how to resolve this issue. I tried to implement the example in thie link for loop inside gnuplot? but it gives me an error saying: ':' expected .I have gnuplot 4.2 installed. Thanks, #!/bin/bash for Counter in {1..9}; do FILE="dataFile"$Counter".data" gnuplot <<EOF set

Javascript for…of doesn't work in Safari

雨燕双飞 提交于 2020-01-13 12:07:13
问题 Currently I am trying to build a simple sidenavigation that appears/disappears whenever one of the "toggleSidenav" buttons is clicked (there are multiple). It seemed to work fine when testing with Firefox and Chrome but today when I tried to open my page with Safari (desktop and mobile version) the buttons didn't do anything. The problem seems to be the for-of-loop I used but checking the reference of the for...of, Safari should support it. My code: for (var btn of document