vectors

(R) How to tell what is in one vector and not another?

In matlab there is a way to find the values in one vector but not in the other. for example: x <- c(1,2,3,4) y <- c(2,3,4) is there any function that would tell me that the value in x that's not in y is 1? ...

Euclidean distance vs Pearson correlation vs cosine similarity?

Their goals are all the same: to find similar vectors. Which do you use in which situation? (any practical examples?) ...

Help with Vector.size() in Java

I'm implementing a Graph which holds "Book" objects as its nodes. The nodes are connected if the books share a keyword. The keywords for each book are held in a Vector within the Book class. To do this, I've created 3 classes. 1) Books 2) Vertex 3) Graph The Vertex class holds the Book object and also has a Vector containing all the ot...

Mixing two RGB color vectors to get resultant

I am trying to mix two source RGB vectors to create a third "resultant vector" that is an intuitive mix of the first two. Ideally, I would be able to emulate "real paint mixing characteristics", but for simplicity, I am trying to find a method where the resultant looks intuitively like what you'd get from combining the two source rgb's...

Rotation Question

I have lot of points (which together form a 3d ellipse) in a given frame (X, Y, Z) and then I have vector (u,v,w). What I want is to orient the ellipse along the vector (u,v,w) . Anyone has useful thoughts on how to go about doing that? ...

turn a line into a rectangle

I have a method that draws a line between two points. This works pretty well, but now I want to make this line into a rectangle. How can I get the points on the left and right side of each of the line points to make it into a rectangle that I can draw? It is almost as though I need to somehow figure out how to get perpendicular lines ...

How add objects dynamically

This is the question : How to do IT Right ? IT = add objects dynamically (mean create class structures to support that) class Branch { Leaves lv; //it should have many leaves!! } class Tree { Branch br; //it should have many branchs!!! } Now a Non-Working Example (neither is c++ !!, but I t...

Can I treat a struct like an array?

I have a struct for holding a 4D vector struct { float x; float y; float z; float w; } vector4f And I'm using a library that has some functions that operate on vectors but take float pointers as their arguments. Is it legal to call something like doSomethingWithVectors( (float *) &myVector)? ...

Automatic Clustering With Hash/Map of Vectors in C++

I have the following values for example: 0 0 0 1 3 2 These values refers to cluster Ids, where the member of the cluster is the index of the vector. Hence we want to get this sort of output: Cluster 0 -> 0,1,2 Cluster 1 -> 3 Cluster 2 -> 5 Cluster 3 -> 4 I tried the following construct but it doesn't seem to work: What's the way t...

Searching c++ std vector of structs for struct with matching string

I'm sure I'm making this harder than it needs to be. I have a vector... vector<Joints> mJointsVector; ...comprised of structs patterned after the following... struct Joints { string name; float origUpperLimit; float origLowerLimit; }; I'm trying to search mJointsVector with "std::find" to locate an individual joint...

Normal Vector of Three Points

Hey math geeks, I've got a problem that's been stumping me for a while now. It's for a personal project. I've got three dots: red, green, and blue. They're positioned on a cardboard slip such that the red dot is in the lower left (0,0), the blue dot is in the lower right (1,0), and the green dot is in the upper left. Imagine stepping ba...

Generating triangular/hexagonal coordinates (xyz)

I'm trying to come up with an iterative function that generates xyz coordinates for a hexagonal grid. Maths has never been easy for me (I'm just not very clever!) and this problem has me stumped. With a starting hex position (say 0,0,0 for simplicty) I want to calculate the coordinates for each successive "ring" of hexagons, as illustrat...

C++ - Deleting a vector element that is referenced by a pointer

Hi all! Well, I don't know if it is possible, but the thing would be: struct stPiece { /* some stuff */ stPiece *mother; // pointer to the piece that created this one }; vector<stPiece> pieces; Is it possible to erase the piece referenced by 'mother' from pieces, having just that pointer as a reference? How? Would it mess with t...

Compute Median of Values Stored In Vector - C++?

Hi there, I'm a programming student, and for a project I'm working on, on of the things I have to do is compute the median value of a vector of int values. I'm to do this using only the sort function from the STL and vector member functions such as .begin(), .end(), and .size(). I'm also supposed to make sure I find the median whether ...

Rotation matrix for a bicycle

Assume you have a flat plane, with a bicycle resting on it. As the bicycle enters a turn, it leans into the turn with angle theta. At the same time, the bike frame points in the same direction as the bike velocity. Thus, given the bike velocity vector v (assumed to be in the XZ plane) and the lean angle theta, how can you find the rot...

Mapping 2 vectors - help to vectorize

Working in Matlab I have 2 vectors of x coordinate with different length. For example: xm = [15 20 24 25 26 35 81 84 93]; xn = [14 22 26 51 55 59 70 75 89 96]; I need to map xm to xn, or in other words to find which coordinates in xn are closest to xm. So if I have values associated with those coordinates, I can use this map as index ...

Push_back causeing an error when using vectors in C++

I am having issues getting this piece of code to compile. I am compiling with Eclipse on OS X 10.6. The problem seems to occur only when using vectors. I cannot seem to use the push_back function at all. Every time I try, I get the error "expected constructor, destructor, or type conversion before '.' token". Here are a few snippets of m...

Find the first point along a heading that is a specified distance away from a line segment.

Hi, Given a starting point, a heading, a distance, and a line segment, find the first point along this heading that is the specified distance away from this line segment. I covered two cases, but I haven't been able to cover the last one. First case: heading away from the line. Ignore it even if the starting point is within the specifie...

How do I label two vectors in Matlab?

I have a 2 column matrix(called M, which I visualize as two vectors using Matlab's plot command(plot(M)). I have two issues: I want to label the vectors themselves on the plot. I want to label each row of the matrix(i.e. each vector component) on the plot. How would I go about doing those things? ...

quick vector initialization c++

Possible Duplicates: C++: Easiest way to initialize an STL vector with hardcoded elements Using STL Allocator with STL Vectors out of curiosity i want to know quick ways of initializing vectors i only know this double inputar[]={1,0,0,0}; vector<double> input(inputar,inputar+4); ...