for-loop

A For loop to replace vector value

自古美人都是妖i 提交于 2021-01-07 02:52:13
问题 I couldn't figure out what's the problem on my code. Basically i'm trying to do a small version of Monte Carlo simulation. This is my input mydata=[1,4,20,23,37] prediction=c(0,0,0,0,0,0,0,0,0,0,0,0) randomvar=runif(12,0,1) and then i have this condition: if i-th value of randomvar is > 0.97, replace i-th value of prediction with 5th data from mydata else if i-th value of randomvar is > 0.93, replace i-th value of prediction with 4th data from mydata else if i-th value of randomvar is > 0.89,

MATLAB: Count punctuation marks in table columns

浪尽此生 提交于 2021-01-07 02:43:57
问题 I'm trying to find the amount of sentences in this table: Download Table here: http://www.mediafire.com/file/m81vtdo6bdd7bw8/Table_RandomInfoMiddle.mat/file As you can see by the full-stops, there is one sentence in column one, and 2 sentences in column 3. At the end of the day I desire to have a table with nothing but punctuation marks(with the exception of place holders like "", to keep the table rows the same length) that indicate the end of a sentence(Like "." or "?" or "!"), in order to

Array of strings won't print

醉酒当歌 提交于 2021-01-07 02:33:39
问题 I'm making a program where a teacher can enter the number of students and their full name. I don't know what I'm doing wrong because this is the first time I'm trying to print an array of strings. This is the part of my program that I'm having trouble with: #include <stdio.h> int main() { int n_students,i,b=1; char surname[20],first_name[20]; printf("number of students:"); scanf("%d",&n_students); for(i=0;i<n_students;i++) { printf("%d. ",b); scanf("%s %s",&surname[i],&first_name[i]); } for(i

Why is “ECHO is off” displayed after output of data of interest on running WMIC in a FOR loop?

亡梦爱人 提交于 2021-01-05 06:50:36
问题 Here is the code: @echo off setlocal EnableDelayedExpansion for /f "tokens=* skip=1 delims=\" %%b in ('wmic /node:%CompName% COMPUTERSYSTEM GET USERNAME') do echo %%b Output: domain\username ECHO is off. Expected result: username Notes: The variable CompName will be set prior. This can be ignored. This code is a part of a larger code I am writing for this batch file where I'll just need to pull the username to have it set as a variable. Pseudo code: set TargetUsername = (results from above)

Alternative to using loop to make code run faster

蓝咒 提交于 2021-01-03 05:40:20
问题 I have 2 questions, the first one is about an excel formula that i can't replicate in VBA even though i've used the record macro to retrieve the formula, the second comes because i couldnt solve my first question and is about code efficiency: Basically in the cell AR2 i'm putting an excel formula : IF=(P2="LDN";"UK;IF(P2="MAD";"SPAIN" IF(P2="PRA";"CZECH REPUBLIC";""))))))))) i m doing this for a bunch of countries. and then i m doing the autfill cell destination on my second row till the last

Function doesn't return all results from 'for' loop

核能气质少年 提交于 2021-01-03 05:24:48
问题 I've made a simple function to print out a times table chart depending on the number you decide to run with. The problem I'm having due to my basic understanding of the language is why it only returns the first loop and nothing else. def timestables(number): for a in range(1, number+1): b = a*a c = a return (str(c) + " * " + str(c) + " = " + str(b)) print(timestables(5)) I get the answer .. 1 * 1 = 1 I've tried to rectify this issue by using print instead of return but this ultimately results

Function doesn't return all results from 'for' loop

亡梦爱人 提交于 2021-01-03 05:22:45
问题 I've made a simple function to print out a times table chart depending on the number you decide to run with. The problem I'm having due to my basic understanding of the language is why it only returns the first loop and nothing else. def timestables(number): for a in range(1, number+1): b = a*a c = a return (str(c) + " * " + str(c) + " = " + str(b)) print(timestables(5)) I get the answer .. 1 * 1 = 1 I've tried to rectify this issue by using print instead of return but this ultimately results

How to safely echo FOR variable %%~p followed by a string literal

不问归期 提交于 2021-01-01 05:00:50
问题 I have a variable %%p created from for /f command When i try to use it with some additional references like: %%~dp and then write some text afterwards it accesses a different variable set var="%%~dpabc.txt" Code outputs %%~dpa instead of %%~dp 回答1: So you must be using FOR /F with multiple tokens, like for /f "tokens=1-16" %%a in (file) do echo %%~dpabc.txt Or your code could have nested FOR loops. Something like for %%a in (something) do ( for %%p in (somethingelse) do ( echo %%~dpabc.txt )

How do I make a list of imported classes in Python?

百般思念 提交于 2021-01-01 00:44:23
问题 from module import a, b, c foo(a) foo(b) foo(c) Is there a way to avoid having to call foo(x) for each imported object? Some context: a, b, c are webpage classes and foo is a route() function that creates a route for each webpage. Update: There will be a growing list of imported classes in the main module as the application grows. I mentioned a, b, and c simply as an example. I am looking for something like import a, b, c to classes_list and then I can iterate over the classes_list instead of

R programming, row-wise data frame calculation with custom script (for every i) to solve “bridge game”

跟風遠走 提交于 2020-12-31 06:46:11
问题 I have a data frame which specifies "bridge games" (every row is one independent game), see a minimal example with 4 games below: start <- list(c("10","15","5"), c("5") ,c("11","6"),c("6","11")) end <- list(c("7","17","11"), c("10"), c("8","12"),c("8","12")) ascending <- c("+","-","+","-") position <- c(11,6,9,8) desired_output <- c(5,5,"disqualified",3) bridge_game <- data.frame(start = I(start), end = I(end), ascending = ascending, position = position, desired_output = desired_output)