Code:

clear all;
clc;
%%%%%%%%%%%%%%% Better RBY IV Calculator %%%%%%%%%%%%%%%%%%%%%%
BaseStats=[65,60,70,85,75,40]; %% Enter the Base Stats AS LISTED IN Game:
%% HP, Attack, Defense, Sp. Attack, Sp. Def, Speed
EVs=[0,0,0,0,0,0]; %% This number must be known. If you don't know it, use
%% HP Up, Protein, Iron,
%% Calcium, Carbos says "It will have no
%% effect", then use the default
%% value 25600 for each stat.
Stats=[23,11,13,15,14,9]; %% Enter the Actual (Visible) Stats AS LISTED IN Game:
%% HP, Attack, Defense, Special (Attack/Defense), Speed
Breed = true;
Female = true;
FMRatio = [0 0]; %% ratio of female to male
%% [1 7]
%% [1 3]
%% [1 1]
%% [3 1]
%% [0 0] for All Female / Genderless
MotherIVs = [15 15]; % Defense / Special, since those stats are inherited
Level=5; %% Enter the level of the Pokemon here.
HPIVs=[];
AtkIVs=[];
DefIVs=[];
SpAIVs=[];
SpDIVs=[];
SpeIVs=[];
%%% First, Calculate HP %%%
for HPIV=0:15 %%% HP
X=floor((HPIV+BaseStats(1)+sqrt(EVs(1))/8+50)*Level/50)+10;
if X==Stats(1)
HPIVs=[HPIVs HPIV];
end
end
%%% Now, for the rest of the stats %%%
for AtkIV=0:15 %%% Attack
X=floor((AtkIV+BaseStats(2)+sqrt(EVs(2))/8)*Level/50)+5;
if X==Stats(2)
AtkIVs=[AtkIVs AtkIV];
end
end
for DefIV=0:15 %%% Defense
X=floor((DefIV+BaseStats(3)+sqrt(EVs(3))/8)*Level/50)+5;
if X==Stats(3)
DefIVs=[DefIVs DefIV];
end
end
for SpAIV=0:15 %%% Special Attack (Same as Special)
X=floor((SpAIV+BaseStats(4)+sqrt(EVs(4))/8)*Level/50)+5;
if X==Stats(4)
SpAIVs=[SpAIVs SpAIV];
end
end
for SpDIV=0:15 %%% Special Defense (Same as Special)
X=floor((SpDIV+BaseStats(5)+sqrt(EVs(5))/8)*Level/50)+5;
if X==Stats(5)
SpDIVs=[SpDIVs SpDIV];
end
end
for SpeIV=0:15 %%% Speed
X=floor((SpeIV+BaseStats(6)+sqrt(EVs(6))/8)*Level/50)+5;
if X==Stats(6)
SpeIVs=[SpeIVs SpeIV];
end
end
%%% Do a female/male comparison
if Female == true
if FMRatio == [1 7]
GenderAtkRange = 0:1;
elseif FMRatio == [1 3]
GenderAtkRange = 0:4;
elseif FMRatio == [1 1]
GenderAtkRange = 0:6;
elseif FMRatio == [3 1]
GenderAtkRange = 0:11;
elseif FMRatio == [0 0]
GenderAtkRange = 0:15;
end
else
GenderAtkRange = 0:15;
end
AtkIVs = unique(andM(AtkIVs,GenderAtkRange));
SpcIVs = unique(andM(SpAIVs,SpDIVs)); %%% Do a set comparison since SpA = SpD = Spc
%%% Do a set comparison with the HP IVs based on the HP Formula %%%
if Breed == true
DefIVs = MotherIVs(1);
SpcM = MotherIVs(2);
if (SpcM < 8)
SpcM = [SpcM SpcM+8];
else
SpcM = [SpcM SpcM-8];
end
SpcIVs = unique(andM(SpcIVs,SpcM));
end
% HPIVs
if isempty(HPIVs)
disp('HP = Invalid IVs (Possible Invalid IVs). Please verify your stats.');
else
disp(strcat('HP = [',num2str(HPIVs),']'));
end
% AtkIVs
if isempty(AtkIVs)
disp('Atk = Invalid IVs (Possible Gender Attack IV Mismatch). Please verify your stats.');
else
disp(strcat('Atk = [',num2str(AtkIVs),']'));
end
% DefIVs
if isempty(DefIVs)
disp('Def = Invalid IVs(Possible Breeding IV Mismatch). Please verify your stats.');
else
disp(strcat('Def = [',num2str(DefIVs),']'));
end
% SpAIVs
if isempty(SpcIVs)
disp('SpA = Invalid IVs (Possible Special Attack/Defense IV or Breeding Mismatch). Please verify your stats.');
else
disp(strcat('SpA = [',num2str(SpcIVs),']'));
end
% SpDIVs
if isempty(SpcIVs)
disp('SpD = Invalid IVs (Possible Special Attack/Defense IV Mismatch). Please verify your stats.');
else
disp(strcat('SpD = [',num2str(SpcIVs),']'));
end
% SpeIVs
if isempty(SpeIVs)
disp('Spe = Invalid IVs. Please verify your stats.');
else
disp(strcat('Spe = [',num2str(SpeIVs),']'));
end