Creating a two matrices from 2 existing matrices according to a rule

3 views (last 30 days)
Hi all,
I am new to matlab and I have been trying to create a rule for the past couple of days, unfortunately unsuccessful I hope that someone here would be able to help me.
Here is the problem:
I have two matrices Y ( 1 column vector with 10 000 entries) and X (matrix with 4 columns, 10 000 entries in each). I want to create new matrix Y and X according to the following rule, Matrix X should contain the same 4 columns but only 50 observations, and the rule: it should contain the first 50 observations in absolute value from column 3 and the corresponding elements (to the observations in column 3) from column 1, 2 and 4. It should take also the corresponding elements of vector Y to the first 50 observations in absolute value in column 3 of X. And it should save them in new matrices Y1 and X1. And here is the most challenging part: It should do this 200 times increasing the number of observations each time by 50 (meaning the first 50 in absolute value in column 3 in X + the second 50 in absolute value in column X, etc.)
I am really puzzled how to do this and I hope somebody can help me.
Thank you all for your help and time!

Accepted Answer

Image Analyst
Image Analyst on 12 May 2012
What does this mean: "the first 50 observations in absolute value"? Do you mean that you just simply take the absolute value of the column 3, like this:
first50Col3Values = abs(X(1:50, 3));
and I don't understand your most challenging part, aren't you simply taking abs(X(51:100, 3)), abs(X(101:150, 3)) and so on, two hundred times? What's so hard about that?
  1 Comment
Jarek
Jarek on 12 May 2012
Thank you Image Analyst for taking the time to look through my problem.
Yes, you are right.
1. The problem is that I would need a new matrix X1 that contains in column 3 the first 50 observations in absolute value (meaning when you have the absolute values of all the observations in column 3, and then sort them in ascending order and take the first 50(the smallest 50 observations)) and for the remaining columns 1, 2 and 4 the corresponding observations to the those 50 in column 3.
2. The challenge is to repeate this 200 times by increasing the number of observations from first 50 to first 100 to first 150 etc.
I hope this clarifies my question, and I apologize if it’s too simple but I am completely new to matlab and try to learn fast.
Thanks in for your time and effort!

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!