FAQ Database Discussion Community


C++ inheritance, assignment

c++,inheritance,assign
class Base{ ... } a, b; class Derived{ ... } c, d; a = c; // why does this work? d = b; // and why doesn't this work? d = static_cast<Derived>(b) // does this actually work? And what happens exactly when assigning a base class to a derived class...

how to substitute a javascript yahoo weather api call property with a variable

javascript,variables,assign
This is a script that work fine and reads yahoo weather api <script> var callbackFunction = function(data) { var windy = data.query.results.channel.wind; alert(windy.chill); }; </script> <script src="https://query.yahooapis.com/v1/public/yql?q=select wind from weather.forecast where woeid in (select woeid from geo.places(1) where text='chicago, il')&format=json&callback=callbackFunction"></script> But I need to substitute a variable into var windy...

Interview: practical uses of assign-by-reference (as opposed to pass-by-reference)

c++,reference,variable-assignment,assignment-operator,assign
I once landed an interview and was asked what the purpose of assigning a variable by reference would be (as in the following case): int i = 0; int &j = i; My answer was that C++ references work like C pointers, but cannot assume the NULL value, they must...

How to assign a value to a matrix created with assign() in R

r,assign
m <- "mData" assign(m, matrix(data = NA, nrow = 4, ncol = 5)) Now I want to use variable m to assign values to the mData matrix assign(m[1, 2], 35) will not work. Any solution will be much appreciated?...

Assigning values from submatrices to larger matrix

r,matrix,replace,assign,submatrix
I have a bunch of small matrices, which are basically subsets of a larger matrix, but have different values. I want to take the values from these submatrices and overwrite the corresponding values in the larger matrix. For instance, say this is my larger matrix: AB-2000 AB-2600 AB-3500 AC-0100 AD-0100...

How to use assign to modify part of a vector in R?

r,assign
The R help for assign says: "assign does not dispatch assignment methods, so it cannot be used to set elements of vectors, names, attributes, etc." Lower down, in the examples, we are shown: a <- 1:4 assign("a[1]", 2) a[1] == 2 # FALSE get("a[1]") == 2 # TRUE I would...

Assign the value from a text field into an int variable to do some math with other variables and then return it?

ios,xcode,variables,textfield,assign
The code showing here assigns the value of an variables to the text field I want to do the opposite of that. _Initial.text = [NSString stringWithFormat:@"%f", init]; The opposite of the code above. Please help...

C Best way of modifying values in a function

java,c,function,return,assign
I developed with Java since a few years, now I wanted to learn C and I noticed a few differences. In Java when I want to return something from a function(e.g. read user input i would write String s; s = new Scanner(System.in).nextLine(); In C I would write char s[20];...

R convert character to dataframe column name and then replace values in a column

r,eval,assign
I was able to get content of the column pointed by character variable b. But i want to make column emp 0. How could i do that? emp=c(1,2,30) abc=data.frame(emp) b="emp" #below line gives content of column emp eval(parse(text=paste("abc$", b, sep = ""))) #how can i replace each value in column...

Delphi - Use a string variable's name in assignfile()

file,delphi,variables,assign
Is it possible to use a variable in the assignfile command? Eg. f : Textfile ; sFile : string ; {contains 'MyFile.txt' as content} ... cFileDir = 'C:\Users\User\Desktop\Data Engine\Data\Country' ; ... Assignfile(f, cFileDir + '\' + sFile) ; ... I appreciate your help very much. if it's unclear I'll edit...

Why does `mylist[:] = reversed(mylist)` work?

python,list,reverse,assign,python-internals
The following reverses a list "in-place" and works in Python 2 and 3: >>> mylist = [1, 2, 3, 4, 5] >>> mylist[:] = reversed(mylist) >>> mylist [5, 4, 3, 2, 1] Why/how? Since reversed gives me an iterator and doesn't copy the list beforehand, and since [:]= replaces "in-place",...

R: Using the “names” function on a dataset created within a loop

r,paste,assign,names
I am using a for loop to read in multiple csv files and naming the datasets import1, import2, etc. For example: assign(paste("import",i,sep=""), read.csv(files[i], header=FALSE)) However, I now want to rename the variables in each dataset. I have tried the following: names(as.name(paste("import",i,sep=""))) <- c("xxxx", "yyyy") But get the error "target of...

verilog assignment results in undefined 'X' output — why?

verilog,assign
I know VHDL, and just learning verilog. I'm trying to do a simple assignment with bit shift, and I get undefined 'X' in the result. I don't understand why. This is in simulation with Xilinx ISim software. This assignment: assign dout = $signed(data_out >>> shift_bits); Results in 'X' wherever a...

Why am I getting 'output argument not assigned during call to' error in Matlab

matlab,variables,assign
I have a function that Finds the Critical Points of a function. function [ cr ] = CritPt(f, var1, var2) f = sym(f); fx = diff(f,var1); fy = diff(f,var2); [xcr,ycr] = solve(fx,fy); crpt = [xcr,ycr] I am supposed to use the function CritPt in the Command Window to define a...

Reassigning vector values using nested for-loops in matlab?

arrays,matlab,for-loop,vector,assign
In matlab I have two vectors, ind and ind3. ind = [1 2 3 4 5] and I want to define ind3 based on ind such that I want ind(3), ind(4) and ind(5) to be ind3(1) and ind3(2) and ind3(3). so that ind3 = [ind(3) ind(4) ind(5)] but for some...

Assign to a variable data frame in R

r,dataframes,assign
I am trying to assign a column of data to a new column in an existing data frame. The data frame changes in a loop, from scores.d, to scores.e. My desired output is to have scores.X$new.col populated with the vals, where X is replaced with the current dfname. dfnames <-...

Java: instanciate variables from array

java,arrays,assign
In Python you can do the following: myList = [1, 2, 3, 4] a, b, c, d = myList print a # -> 1 print d # -> 4 Is there a way to do such a thing in Java? Better/faster than below: int[] myList= {1, 2, 3, 4}; int...

value name as string in assign function

r,string,object,assign
I want to use different data frames in a loop. I am having trouble with accesing the different data frames within the loop. Data1<-data.frame(X=rnorm(100,2), Y=rnorm(200,2), Z=rnorm(200,2)) Data2<-data.frame(X=rnorm(300,500), Y=rnorm(300,500)) Data3<-data.frame(X=rnorm(500,200), Y=rnorm(20,200)) for (i in c(1:3)){ assign("CurrentData", paste("Data", i, sep="")) colMeans(CurrentData) } The assign function does not do what I want because...

R Assign to the ith index in a list, the name of which is called variably in a loop?

r,list,variables,indexing,assign
First, this is a tough one to explain, particularly given that I am new to coding/R and its nomenclature, so I appreciate your patience and time (Destiny reference!). I have a list of data frame names, in a loop I pull one out, then I enter a second loop, in...

UIImage gets released at the end the function after assignment has been made

ios,objective-c,uiimage,assign
I have a ViewController that holds a custom UIView as its member like this: @property (nonatomic, strong) IBOutlet ProfileUIView * profileUIView;in my ViewController i get back a UIImage from an imagePickerController:didFinishPickingMediaWithInfo: and there i'm assigning the UIImage i get to a local UIImage variable in my ProfileUIView. i see that...

Trouble setting and adding array values javascript

javascript,forms,add,assign
I want to give each check box an integer value and then if the box is checked add the values and display the total in a text box with the ID="options". So far the code is not sending a value to the desired location. Any instruction on how to improve...

Assign And Weak

ios,objective-c,assign,weak
I want to look a difference between assign and weak.So I run this code below: @interface Test : NSObject @property(nonatomic, strong) NSString *str; @property(nonatomic, assign) NSString *assignString; @property(nonatomic, weak) NSString *weakString; @end @implementation Test - (id)init { self =[super init]; if (self) { self.str = @"i'm test string"; self.assignString =...

Assigning a value for each dataset and plot it with ggplot

r,ggplot2,lapply,assign,seq
It can be complicated problem but I will try to explain it as much as I could. I have a sequenced dataset containing number of observations which should be processed before plotting. I want do it with a function. because I have another datasets in the directory (around 20) #reproducible...

Hungarian algorithm in PHP with multiple assignments

php,algorithm,assign,subgraph,pairing-heap
In the following we are facing the problem of multiple assignments of the hungarian algorithm. Scenario: We have 100 students and 5 courses, which the students can vote with priority. So every student will get assigned for one specific cours. Priority from 1 to 5. 1 lowest 5 highest The...

Assigning a string from a .txt file into a variable

python,string,variables,assign
I have a .txt file with one column and about 35 rows, I have some code to assess the strings but i'm unsure how to assign each string as a variable to have it as [imported variable] = [rest of code] So far i have: import numpy as np np.genfromtxt("C:\Users\...\x.txt",...

Using multiple boolean arrays for indexing and assigning

python,arrays,numpy,indexing,assign
I just came across the following issue I really do not understand: import numpy as np a = np.arange(10) m = a < 5 n = a[m] < 2 print a[m][n] # array([0, 1]) So far so good. Here comes the problem: a[m][n] *= 10000 print a[m][n] # array([0, 1])...

Non-blocking and blocking assignments don't work as expected

concurrency,verilog,simulation,blocking,assign
I'm having problems with understanding such a simply looking thing: blocking and non-blocking assignments. I created a small test bench just to simulate the behavior of this code: module ATest(clk, out); input wire clk; output reg [7:0] out; reg [7:0] A; initial begin A <= 8'b0; end always @(posedge clk)...