%unit hypercubes - by Ankur Kumar
%the vertices are retreived by creating a table, kind of like a truth table
% graph x-dimensional cube
function v = hypercube(x)

%clear
clf
%clear all

%dimensions
ndim = x;
index = ndim-1;
%vertices coords matrix
v = [];
%finding vertices of n-D cube, which are the elements of a n-D truth table, using repmat
for i = 0:index
    temp = [zeros(2^i,1);ones(2^i,1)];
    col = repmat(temp,2^(index-i),1);
    v = [v,col]; 
end

%plot in parallel coordinates
H = figure(1);
title(sprintf('%d-Dimensional Hypercube',ndim));
hold on
for i = 1:2^ndim
    plot(v(i,:),'r');
end

%the axes for parallel coords
axisx = [1;ndim];
axisy = [0;0];
label = [];
for i = 1:ndim
    axisx = [axisx,[i;i]];
    axisy = [axisy,[0;1]];
    label = [label, {sprintf('x%d',i)}];    %used for labelling the axes
end
line(axisx, axisy, 'color', 'b');           %draw the axes
set(gca, 'xtick',[1:1:ndim]);
set(gca, 'xticklabel', label);

