# How to keep numbers that are smaller than a certain value?

1 view (last 30 days)
Luca on 2 May 2021
Answered: Daksh on 26 Sep 2022
Hi, I created a table with the value of the 20% percentile for a certain year. I have a second table with diffrent stocks and market capitalization and years.
Right know i Want to keep only the values that are smaller than the value of the 20% percentile according to the year. For example the first year is 1962 so I want to keep all values of the stocks in 1962 which have a smaller market capitlization than the 20% percentile in 1962. The second year is 1963 than I want to keep the stocks in 1963 which are smaller than the 20% percentile in 1963. The goal is to get a new table which only includes the 20 % of the smallest stocks of every year.
I attached the two tables at this question for better understanding. PRCtbl is the one with the percentile values in it and MRCtable is the one with the marketcapitalisation.
Does someone know how to do that and could help me with it?

Daksh on 26 Sep 2022
It is my understanding that you have created 2 tables with 20% percentile value for each year and stock-market capitalizations for each year respectively and you intend to create a new table that reads these both tables and extract 20% of the smallest stocks for each year.
To achieve this after importing both tables (MCTable and PRCtbl02) into your workspace, you can iterate over all rows of the table (MCTable) with market capitalizations and pick each suitable row with value < 20% percentile for that respective year, and keep on appending it to an output table (newly created table initially). The following code illustrates how to achieve the above:
%Create an empty table
t=table;
%Iterate over all rows in the table
for i=1:size(MCtable,1)
%year represents each for respective value
year=MCtable.years(i);
%this if condition is the necessary condition for value <20% value
if(MCtable.SumMC(i)<PRCtbl02.Var2(year-1962+1))
%appending value to table
t=[t;MCtable(i,:)];
end
end
Hope this helps.

### Categories

Find more on Tables in Help Center and File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!