Radar plot Area Fill - Matlab - matlab

This is a radar plot script for MATLAB I copied from Google Search. I was hoping to use radar plot with different scales with 4 or 5 axes.
How would I fill the graph of this radar plot? Should I use patch or fill? I know this shouldn't take a long time to do this. My math isn't that great.
Thanks in advance,
Gary
function [f, ca, o] = spider(data,tle,rng,lbl,leg,f)
% create a spider plot for ranking the data
% function [f, ca, o] = spider(data,tle,rng,lbl,leg,f)
%
% inputs 6 - 5 optional
% data input data (NxM) (# axes (M) x # data sets (N)) class real
% tle spider plot title class char
% rng peak range of the data (Mx1 or Mx2) class real
% lbl cell vector axes names (Mxq) in [name unit] pairs class cell
% leg data set legend identification (1xN) class cell
% f figure handle or plot handle class real
%
% outptus 3 - 3 optional
% f figure handle class integer
% x axes handle class real
% o series object handles class real
%
% michael arant - jan 30, 2008
%
% to skip any parameter, enter null []
%
% examples
%
% spider([1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15;16 17 18; ...
% 19 20 21; 22 23 24; 25 26 27]','test plot');
%
% spider([1 2 3 4; 4 5 6 7; 7 8 9 10; 10 11 12 13; 13 14 15 16; ...
% 16 17 18 19; 19 20 21 22; 22 23 24 25; 25 26 27 28],'test plot', ...
% [[0:3:24]' [5:3:29]'],[],{'Case 1' 'Case 2' 'Case 3' 'Case 4'});
%
% spider([1 2 3 4; 4 5 6 7; 7 8 9 10; 10 11 12 13; 13 14 15 16; ...
% 16 17 18 19; 19 20 21 22; 22 23 24 25; 25 26 27 28],'test plot', ...
% [],[],{'Case 1' 'Case 2' 'Case 3' 'Case 4'});
%
% figure; clf; set(gcf,'color','w'); s = zeros(1,4);
% for ii = 1:4; s(ii) = subplot(2,2,ii); end
%
% spider([1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15;16 17 18; ...
% 19 20 21; 22 23 24; 25 26 27]','test plot 1',[],[],[],s(1));
%
% spider([1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15;16 17 18; ...
% 19 20 21; 22 23 24; 25 26 27],'test plot 2',[0 30],[],[],s(2));
%
% spider([1 2 3 4; 4 5 6 7; 7 8 9 10; 10 11 12 13; 13 14 15 16; ...
% 16 17 18 19; 19 20 21 22; 22 23 24 25; 25 26 27 28]','test plot 3', ...
% [0 30],{'Label 1' 'Unit 1'; 'Label 2' 'Unit 2'; 'Label 3' 'Unit 3'; ...
% 'Label 4' 'Unit 4'},{'Case 1' 'Case 2' 'Case 3' 'Case 4' 'Case 5' ...
% 'Case 6' 'Case 7' 'Case 8' 'Case 9'},s(3));
%
% spider([1 2 3 4; 4 5 6 7; 7 8 9 10; 10 11 12 13; 13 14 15 16; ...
% 16 17 18 19; 19 20 21 22; 22 23 24 25; 25 26 27 28],'test plot 4', ...
% [[0:3:24]' [5:3:29]'],[],{'Case 1' 'Case 2' 'Case 3' 'Case 4'},s(4));
% data check
if nargin < 1; help spider; error('Need data to plot'); end
% size segments and number of cases
[r c] = size(data);
% exit for too few axes
if r < 3
errordlg('Must have at least three measuremnt axes')
error('Program Termination: Must have a minimum of three axes')
end
% title
if ~exist('tle','var') || isempty(tle) || ~ischar(tle)
tle = 'Spider Plot';
end
% check for maximum range
if ~exist('rng','var') || isempty(rng) || ~isreal(rng)
% no range given or range is in improper format
% define new range
rng = [min([min(data,[],2) zeros(r,1)],[],2) max(data,[],2)];
% check for negative minimum values
if ~isempty(ismember(-1,sign(data)))
% negative value found - adjust minimum range
for ii = 1:r
% negative range for axis ii - set new minimum
if min(data(ii,:)) < 0
rng(ii,1) = min(data(ii,:)) - ...
0.25 * (max(data(ii,:)) - min(data(ii,:)));
end
end
end
elseif size(rng,1) ~= r
if size(rng,1) == 1
% assume that all axes have commom scale
rng = ones(r,1) * rng;
else
% insuffent range definition
uiwait(msgbox(char('Range size must be Mx1 - number of axes x 1', ...
sprintf('%g axis ranges defined, %g axes exist',size(rng,1),r))))
error(sprintf('%g axis ranges defined, %g axes exist',size(rng,1),r))
end
elseif size(rng,2) == 1
% assume range is a maximum range - define minimum
rng = sort([min([zeros(r,1) min(data,[],2) - ...
0.25 * (max(data,[],2) - min(data,[],2))],[],2) rng],2);
end
% check for axis labels
if ~exist('lbl','var') || isempty(lbl)
% no labels given - define a default lable
lbl = cell(r,1); for ii = 1:r; lbl(ii) = cellstr(sprintf('Axis %g',ii)); end
elseif size(lbl,1) ~= r
if size(lbl,2) == r
lbl = lbl';
else
uiwait(msgbox(char('Axis labels must be Mx1 - number of axes x 1', ...
sprintf('%g axis labels defined, %g axes exist',size(lbl,1),r))))
error(sprintf('%g axis labels defined, %g axes exist',size(lbl,1),r))
end
elseif ischar(lbl)
% check for charater labels
lbl = cellstr(lbl);
end
if ~exist('leg','var') || isempty(leg)
% no data legend - define default legend
leg = cell(1,c); for ii = 1:c; leg(ii) = cellstr(sprintf('Set %g',ii)); end
elseif numel(leg) ~= c
uiwait(msgbox(char('Data set label must be 1XN - 1 x number of sets', ...
sprintf('%g data sets labeled, %g exist',numel(leg),c))))
error(sprintf('%g data sets labeled, %g exist',numel(leg),c))
end
% check for figure or axes
if ~exist('f','var')
% no figure or axes requested - generate new ones
f = figure; ca = gca(f); cla(ca); hold on; set(f,'color','w')
elseif ismember(f,get(0,'children')')
% existing figure - clear and set up
ca = gca(f); hold on;
elseif isint(f)
% generating a new figure
figure(f); ca = gca(f); cla(ca); hold on
else
% may be an axes - may be garbage
try
%is this an axes?
if ismember(get(f,'parent'),get(0,'children')')
% existing figure axes - use
ca = f; f = get(f,'parent'); hold on
end
catch
% make new figure and axes
disp(sprintf('Invalid axes handle %g passed. Generating new figure',f))
f = figure; ca = gca(f); cla(ca); hold on
end
end
% set the axes to the current text axes
axes(ca)
% set to add plot
set(ca,'nextplot','add');
% clear figure and set limits
set(ca,'visible','off'); set(f,'color','w')
set(ca,'xlim',[-1.25 1.25],'ylim',[-1.25 1.25]); axis(ca,'equal','manual')
% title
text(0,1.3,tle,'horizontalalignment','center','fontweight','bold');
% define data case colors
col = color_index(c);
% scale by range
angw = linspace(0,2*pi,r+1)';
mag = (data - rng(:,1) * ones(1,c)) ./ (diff(rng,[],2) * ones(1,c));
% scale trimming
mag(mag < 0) = 0; mag(mag > 1) = 1;
% wrap data (close the last axis to the first)
ang = angw(1:end-1); angwv = angw * ones(1,c); magw = [mag; mag(1,:)];
% make the plot
% define the axis locations
start = [zeros(1,r); cos(ang')]; stop = [zeros(1,r); sin(ang')];
% plot the axes
plot(ca,start,stop,'color','k','linestyle','-'); axis equal
% plot axes markers
inc = 0.25:.25:1; mk = .025 * ones(1,4); tx = 4 * mk; tl = 0:.25:1;
% loop each axis ang plot the line markers and labels
% add axes
for ii = 1:r
% plot tick marks
tm = plot(ca,[[cos(ang(ii)) * inc + sin(ang(ii)) * mk]; ...
[cos(ang(ii)) * inc - sin(ang(ii)) * mk]], ...
[[sin(ang(ii)) * inc - cos(ang(ii)) * mk] ;
[sin(ang(ii)) * inc + cos(ang(ii)) * mk]],'color','k');
% label the tick marks
for jj = 1:4
% temp = text([cos(ang(ii)) * inc(jj) + sin(ang(ii)) * tx(jj)], ...
% [sin(ang(ii)) * inc(jj) - cos(ang(ii)) * tx(jj)], ...
% num2str(chop(rng(ii,1) + inc(jj)*diff(rng(ii,:)),2)), ...
% 'fontsize',8);
temp = text([cos(ang(ii)) * inc(jj) + sin(ang(ii)) * tx(jj)], ...
[sin(ang(ii)) * inc(jj) - cos(ang(ii)) * tx(jj)], ...
num2str(rd(rng(ii,1) + inc(jj)*diff(rng(ii,:)),-2)), ...
'fontsize',8);
% flip the text alignment for lower axes
if ang(ii) >= pi
set(temp,'HorizontalAlignment','right')
end
end
% label each axis
temp = text([cos(ang(ii)) * 1.1 + sin(ang(ii)) * 0], ...
[sin(ang(ii)) * 1.1 - cos(ang(ii)) * 0], ...
char(lbl(ii,:)));
% flip the text alignment for right side axes
if ang(ii) > pi/2 && ang(ii) < 3*pi/2
set(temp,'HorizontalAlignment','right')
end
end
% plot the data
o = polar(ca,angw*ones(1,c),magw);
% set color of the lines
for ii = 1:c; set(o(ii),'color',col(ii,:),'linewidth',1.5); end
% apply the legend
temp = legend(o,leg,'location','best');
return
function [v] = rd(v,dec)
% quick round function (to specified decimal)
% function [v] = rd(v,dec)
%
% inputs 2 - 1 optional
% v number to round class real
% dec decimal loaction class integer
%
% outputs 1
% v result class real
%
% positive dec shifts rounding location to the right (larger number)
% negative dec shifts rounding location to the left (smaller number)
%
% michael arant
% Michelin Maericas Research and Development Corp
if nargin < 1; help rd; error('I/O error'); end
if nargin == 1; dec = 0; end
v = v / 10^dec;
v = round(v);
v = v * 10^dec;
function [val] = color_index(len)
% get unique colors for each item to plot
% function [val] = color_index(len)
%
% inputs 1
% len number of objects class integer
%
% outputs 1
% val color vector class real
%
% michael arant
if nargin < 1 || nargout < 1; help color_index; error('I / O error'); end
if len == 1
val = [0 0 0];
else
% initial color posibilities (no white)
% default color scale
col = [ 0 0 0
0 0 1
0 1 1
0 1 0
1 1 0
1 0 1
1 0 0];
% reduce if fewer than 6 items are needed (no interpolation needed)
switch len
case 1, col([2 3 4 5 6 7],:) = [];
case 2, col([2 3 4 5 6],:) = [];
case 3, col([3 4 5 6],:) = [];
case 4, col([3 5 6],:) = [];
case 5, col([5 6],:) = [];
case 6, col(6,:) = [];
end
% number of requested colors
val = zeros(len,3); val(:,3) = linspace(0,1,len)';
% interpolate to fill in colors
val(:,1) = interp1q(linspace(0,1,size(col,1))',col(:,1),val(:,3));
val(:,2) = interp1q(linspace(0,1,size(col,1))',col(:,2),val(:,3));
val(:,3) = interp1q(linspace(0,1,size(col,1))',col(:,3),val(:,3));
end
function [res] = isint(val)
% determines if value is an integer
% function [res] = isint(val)
%
% inputs 1
% val value to be checked class real
%
% outputs 1
% res result (1 is integer, 0 is not) class integer
%
% michael arant may 15, 2004
if nargin < 1; help isint; error('I / O error'); end
% numeric?
if ~isnumeric(val); error('Must be numeric'); end
% check for real number
if isreal(val) & isnumeric(val)
% check for integer
if round(val) == val
res = 1;
else
res = 0;
end
else
res = 0;
end

Related

Assigning Values to the neighbors same value in MATLAB

I am having a small issue but I am clueless where I am at fault. Can someone please guide me the right way? Thanks in advance.
What I have done.
My codes finds local maxima’s.
Bring down from local maxima to a certain point.
Assign the neighbors that are greater than the downsized value, the value of downsized point.
Small Example
X = [1 0 1 4.3 4.5 5 4.3 4.2 0 0 0 2 6.2 6.3 7 6.2 7.4 8 7.2 1 2 3 4 2];
Local maxima’s are 5, 7, 8, and 4
Go down to certain point. Like 4, 6, 7, 3.
Assign neighbors that have values greater than 4,6,7,3 same values.
Output will be like
X = [1 0 1 4 4 4 4 4 0 0 0 2 6 6 6 6 6 6 6 1 2 3 3 2];
As this was a simple example so did not have much difference when I applied my code on it.
I have provided another example with my code. Please have a look at that.
t = 50;
X = sin(2*pi*10*(1:t)/t) + 0.5*sin(2*pi*5*(1:50)/t) - linspace(0,3,50);
% plot(X)
A= X;
% A1 = [1 0 1 4.3 4.5 5 4.3 4.2 0 0 6 6 6 6 6 6 6 6 6 1 2 3 4 2];
[pks,locs] = findpeaks(A);
idx = A(locs)-0.3 ; % will bring local maxima to the point where we want
for b = 1: numel(idx) % loop for checking idx
for c = 1:numel(A) % loop for checking neighbourhoods
if (A(locs(1,b)-c)> idx(1,b) && A(locs(1,b)+c)> idx(1,b))
else
d= c-1;
z(b)= d;
break
end
end
end
for i = 1:numel(idx)
for n = 1:z(1,i)
idx_1 = A(locs(i) - n); % will find what is in neighbourhood of local maxima
idx_2 = A(locs(i) + n);
% idx_1 = A(locs - n); % will find what is in neighbourhood of local maxima
% idx_2 = A(locs + n);
if (idx_1>idx(1,i) && (idx_2>idx(1,i))) % Check and assign the same value to neighbourhood of local maxima
A(locs(1,i)) = idx(i);
A(locs(1,i)-n) = idx(i);
A(locs(1,i)+n) = idx(i);
% A(i)) = A(idx(i))
else if (idx_1 < idx(1,i) && (idx_2>idx(1,i)))
A(locs(1,i)) = idx(i);
A(locs(1,i)+n) = idx(i);
else if (idx_1 > idx(1,i) && (idx_2<idx(1,i)))
A(locs(1,i)) = idx(i);
A(locs(1,i)-n) = idx(i);
else
A(locs(1,i)) = idx(i);
A(locs(1,i)-n) = idx_1(i);
A(locs(1,i)+n) = idx_1(i);
end
end
end
end
A(locs(1,i)) = idx(i);
end
figure(1)
hold on
plot(X,'r')
plot(A,'b')
hold off
Expected Output be like Black line in the picture not blue lines that are formed from code

Matching values from a matrix in a 3-D array

I am trying to match RGB values in an image.
% R G B
RGBset = [ 3 9 12;
4 8 13;
11 13 13;
8 3 2]
img(:,:,1) = [1 2 3
6 5 4
7 9 8
10 11 12];
img(:,:,2) = [3 4 8;
6 7 8;
11 10 9;
12 13 14];
img(:,:,3)= [3 7 2;
4 9 10;
5 11 12;
6 13 14]
In this image, only one RGB value matches from the RGBset which is [11,13,13], so the expected output is:
[0 0 0;
0 0 0;
0 0 0;
0 1 0]; % reshape(img(4,2,:),1,3) = [11, 13 13] is available in RGBset
% no other RGB value is present in the image
I have made this code but it is very slow for larger images.
matched= zeros(img(:,:,1));
for r=1:size(img(:,:,1),1)
for c=1:size(img(:,:,2),2)
matched(r,c)=ismember(reshape(img(r,c,:),1,3),RGBset,'rows');
end
end
What will be the solution with more speed?
We can reduce each RGB triplet into a scalar each and we will do this for both RGBset and img. This would reduce them to 2D and 1D matrices respectively. We are calling this as dimensionality-reduction. With this reduced data, we are achieving memory efficiency and that hopefully should lead to performance boost.
Thus, a solution with those bases covered would look something like this -
% Scaling array for dim reduction
s = [256^2, 256, 1].';
% Reduce dims for RGBset and img
RGBset1D = RGBset*s;
img1D = reshape(img,[],3)*s;
% Finally use find membership and reshape to 2D
out = reshape(ismember(img1D, RGBset1D), size(img,1), []);
Benchmarking for the vectorized solutions
Benchmarking code -
% R G B
RGBset = [ 3 9 12;
4 8 13;
11 13 13;
8 3 2]
% Setup inputs
img = randi(255, 2000, 2000, 3);
img(3,2,:) = RGBset(4,:);
% Luis's soln
disp('--------------------- Reshape + Permute ------------------')
tic
img2 = reshape(permute(img, [3 1 2]), 3, []).';
matched = ismember(img2, RGBset, 'rows');
matched = reshape(matched, size(img,1), []);
toc
% Proposed in this post
disp('--------------------- Dim reduction ------------------')
tic
s = [256^2, 256, 1].';
RGBset1D = RGBset*s;
img1D = reshape(img,[],3)*s;
out = reshape(ismember(img1D, RGBset1D), size(img,1), []);
toc
Benchmarking output -
--------------------- Reshape + Permute ------------------
Elapsed time is 3.101870 seconds.
--------------------- Dim reduction ------------------
Elapsed time is 0.031589 seconds.
You can replace the loops by permute and reshape:
img2 = reshape(permute(img, [3 1 2]), 3, []).';
matched = ismember(img2, RGBset, 'rows');
matched = reshape(matched, size(img,1), []);
This creates a 3-column matrix img2 in which each row corresponds to one pixel from img. That way ismember(..., 'rows') can be applied in a vectorized manner. The obtained result is then reshaped as needed.
You can just loop over the colours, which is much quicker than looping over each pixel.
% Set up your colours into the 3rd dimension, so they match along the same axis
RGB3D = reshape(RGBset,[],1,3);
% Loop over them
for ii = 1:size(RGB3D, 1)
% See if all 3 members of the colour match any pixel
matched = all(ismember(img, RGB3D(ii,:,:)),3)
if any(matched)
disp(matched)
disp(['matched color: ' num2str(ii)]);
% do something else with the matched pixels
end
end

Legend in bar3 in MATLAB

I can't figure out how to create the legends (for colors) in the attached code?
test1=[5 10 7;
1 100 0;
1 3 2];
test2=[10 15 10;
10 80 10;
5 5 15];
test3=[10 10 10;
20 200 20;
30 10 30];
core=bar3(test1);
set(core,'FaceColor',[1 0 0]); %red
for i=1:length(core)
zz=get(core(i),'Zdata');
k=1;
for j= 0:6:(6*length(core)-6)
zz(j+1:j+6,:)=zz(j+1:j+6,:)+test2(k,i);
k=k+1;
end
set(core(i),'Zdata',zz);
end
hold on
core=bar3(test2);
set(core,'FaceColor',[0 1 1]);%cyan
hold off
for i=1:length(core)
zz=get(core(i),'Zdata');
k=1;
for j= 0:6:(6*length(core)-6)
zz(j+1:j+6,:)=zz(j+1:j+6,:)+test3(k,i);
k=k+1;
end
set(core(i),'Zdata',zz);
end
hold on
core=bar3(test3);
set(core,'FaceColor',[1 1 0]);%yellow
hold off
First, I would rename all cores to core1, core2 and core3 to correspond to test1, test2 and test3, and also not to override the handles. Then, if you check the size of each of these using e.g. size(core1), you will see that each of these contains 3 handles to 3 plots. All 3 have the same color, so you can just pick one handle and supply it to the legend as a first argument. So at the end you just need to add
legend([core1(1) core2(1) core3(1)], {'A', 'B', 'C'});
The full code
test1=[5 10 7;
1 100 0;
1 3 2];
test2=[10 15 10;
10 80 10;
5 5 15];
test3=[10 10 10;
20 200 20;
30 10 30];
core1=bar3(test1);
set(core1,'FaceColor',[1 0 0]); %red
for i=1:length(core1)
zz=get(core1(i),'Zdata');
k=1;
for j= 0:6:(6*length(core1)-6)
zz(j+1:j+6,:)=zz(j+1:j+6,:)+test2(k,i);
k=k+1;
end
set(core1(i),'Zdata',zz);
end
legend({'A'});
hold on
core2=bar3(test2);
set(core2,'FaceColor',[0 1 1]);%cyan
hold off
for i=1:length(core2)
zz=get(core2(i),'Zdata');
k=1;
for j= 0:6:(6*length(core2)-6)
zz(j+1:j+6,:)=zz(j+1:j+6,:)+test3(k,i);
k=k+1;
end
set(core2(i),'Zdata',zz);
end
hold on
core3=bar3(test3);
set(core3,'FaceColor',[1 1 0]);%yellow
hold off
legend([core1(1) core2(1) core3(1)], {'A', 'B', 'C'});

How to rewrite this Matlab 2014 code with axis-subplots to 2016?

Code which I wrote for Matlab 2014 but which I want to rewrite it to Matlab 2016 such that it becomes more compact, since it is extranous now
hFig3=figure('Units', 'inches');
hax3_b1=axes('Parent', hFig3);
hax3_b2=axes('Parent', hFig3);
hax3_b3=axes('Parent', hFig3);
hax3_b4=axes('Parent', hFig3);
b1=subplot(2,2,1, hax3_b1);
b2=subplot(2,2,2, hax3_b2);
b3=subplot(2,2,3, hax3_b3);
b4=subplot(2,2,4, hax3_b4);
% Example of common expression
set([b1 b2], 'Units', 'inches'); % http://stackoverflow.com/a/39817473/54964
u=0:0.1:1; y=sin(u); C = [0 2 4 6; 8 10 12 14; 16 18 20 22];
imagesc(b1, u, y, C);
hold on;
plot(b2, u');
histogram(b3, u');
histogram(b4, u);
hold off;
drawnow;
Output is ok
OS: Debian 8.5 64 bit
MATLAB: 2014 but want to convert to 2016
You can simply write:
figure('Units','inches');
b1 = subplot(2,2,1);
b2 = subplot(2,2,2);
b3 = subplot(2,2,3);
b4 = subplot(2,2,4);
or preferably, if you want to have an array of the axes:
figure('Units','inches');
b(1) = subplot(2,2,1);
b(2) = subplot(2,2,2);
b(3) = subplot(2,2,3);
b(4) = subplot(2,2,4);
or use a simple for loop:
figure('Units','inches');
b(1:4) = axes;
for k = 1:numel(b)
b(k) = subplot(2,2,k);
end
In any option you choose there is no need for all the axes commands.
Here is all your 'demo' code:
b(1:4) = axes;
for k = 1:numel(b)
b(k) = subplot(2,2,k);
end
set(b(1:2), 'Units', 'inches');
u=0:0.1:1; y=sin(u); C = [0 2 4 6; 8 10 12 14; 16 18 20 22];
imagesc(b(1), u, y, C);
plot(b(2), u');
histogram(b(3), u');
histogram(b(4), u);
There might be no real need also in the figure command, it depends on what do with it.
If you're just looking for shorter you can eliminate most of the stuff at the beginning. You don't need the figure but I keep it as a matter of habit.
fh = figure;
x = 1:4;
b = arrayfun(#(y) subplot(2,2,y), x, 'UniformOutput',0);
b{1}.Units = 'inches';
b{2}.Units = 'inches';
u=0:0.1:1; y=sin(u); C = [0 2 4 6; 8 10 12 14; 16 18 20 22];
imagesc(b{1}, u, y, C);
plot(b{2}, u');
histogram(b{3}, u');
histogram(b{4}, u);

to find maximum point from the graph/plot

a= [1 2 13 20 10 20 12 1 13 14]
b= [1:10:100]
plot(a,b)
I want to find the maximum('a') from the plot and then take the corresponding point let say 'a3,b3' and store it some where else and remove it from the plot. then I want to subtract 'a3' from every point left in 'a' and plot the graph. and I need to do this again till it reaches an thresh hold point.
This seems like an odd request but if I understand correctly.
%Input data
a = [1 2 13 20 10 20 12 1 13 14];
b = [1:10:100];
%Some threshold (which you didn't specify
lengthA = 4;
%Initialize storage vector
aPrime = a;
bPrime = b;
%While vector
while (length(aPrime) >= lengthA)
%New figure
figure;
%Plot vector
plot(aPrime, bPrime)
%Find index and max value in a'
[aMax, index] = max(aPrime);
%Find max value in b'
bMax = bPrime(index);
%Remove max value from vector and subtract off max value
aPrime = aPrime([1:index - 1, index + 1:end]) - aMax;
bPrime = bPrime([1:index - 1, index + 1:end]) - bMax;
end