Aptech Systems, Inc. Worldwide Headquarters
Mailing Address:
PO Box 250
Black Diamond, WA 98010 USAStreet Address:
30741 Third Avenue #160
Black Diamond, WA 98010 USAPhone: 360.886.7100
FAX: 360.886.8922Ready to Get Started?
For Pricing and Distribution
Industry Solutions
Products
Resources
Support
Training & Events
Want more guidance while learning about the full functionality of GAUSS and its capabilities? Get in touch for in-person training or browse additional references below.
Tutorials
Step-by-step, informative lessons for those who want to dive into GAUSS and achieve their goals, fast.
Have a Specific Question?
Get a real answer from a real person
- Need Support?
Q&A: Register and Login
Support Plans
Premier Support and Platinum Premier Support are annually renewable membership programs that provide you with important benefits including technical support, product maintenance, and substantial cost-saving features for your GAUSS System or the GAUSS Engine.
User Forums
Join our community to see why our users are considered some of the most active and helpful in the industry!
Where to Buy
Available across the globe, you can have access to GAUSS no matter where you are.
Recent Tags
applications character vectors CMLMT covariance matrix dates dlibrary dllcall ECDF Editor error handling errors floating network GAUSS Engine Geometric mean graphics GUI hardware histogram hotkeys if statements installation Java API linux localization Matlab convert matlab translation matrices matrix initialization matrix manipulation Maxlik MaxLikMT Memory output pgraph graph PQG graphics RAM random numbers RedHat 6.1 simulation string functions strings threading threads loops Time Series writing dataRecent Questions
Features
Resources
Rearrange element in vector
1
Suppose i have
v1 = { x1, x2, x3, x4, x5, x6 }
v2 = { x5,x3,x1}
How to rearrange V2 according to position in V1 so that
v3 = { x1,x3,x5}
3 Answers
0
There may be a better way to accomplish this, but you can:
v1 = { x1, x2, x3, x4, x5 };
v2 = { x5, x3, x1 };
//Get the index of each element of v2's location in v1
idx = indcv(v2, v1);
//Sort the indices
idx = sortc(idx, 1);
//Assign v3
v3 = v1[idx];
This code will assign ‘v3′ to be:
x1 x3 x5
You could accomplish the same action for numeric data by using the function indnv instead of indcv.
0
what if i want v4 to be
x1
.
x3
.
x5
0
//Make v4 a missing value v4 = miss(0,0); //Reshape v4 into a 5x1 vector of missing values v4 = reshape(v4, 5, 1); //Use the same idx from the problem above v4[idx] = v1[idx];
Then the print statement:
print $v4;
will return:
X1 . X3 . X5 `
For reference, below is the complete code snippet for both parts:
v1 = { x1, x2, x3, x4, x5 };
v2 = { x5, x3, x1 };
idx = indcv(v2, v1);
//Sort the indices
idx = sortc(idx, 1);
//Assign v3
v3 = v1[idx];
//Make v4 a missing value
v4 = miss(0,0);
//Reshape v4 into a 5x1 vector of missing values
v4 = reshape(v4, 5, 1);
v4[idx] = v1[idx];

