Package hlcd.exporter

Class MatlabCodeWriter

java.lang.Object
hlcd.exporter.MatlabCodeWriter

public class MatlabCodeWriter extends Object
Exports the code found to file as a Matlab .m file. The .m file contains the generator matrix \(G\), the Hermitian transpose \(\overline{G}^{T}\) and \(G^\prime = G \times \overline{G}^{T}\). Similar to CodeExporter, this will not automatically override the file if it already exists because it does use a timestamp. Also, ensures that Matlab calculates \(G \times \overline{G}^{T}\), which must match the matrix this program found. Note: A significant bug has been encountered in Matlab. Even in the latest (when writing this document) version R2021b Update 2 (9.11.0.1847648) Dec 31 2021. To see how it can be bypassed, refer to section 8.2.6 Verifying Results with MATLAB.

A sample output could be:

 % The code (7, 4, 3)_4 Version  created at: Jan 24, 2022 08:18:35 PM
 % It will test the validity of the code found.
 % N    = 7
 % K    = 4
 % D    = 3
 % BASE = 4

 clc
 tic
 fprintf("Run started %s\n\n", datestr(now,'mmmm dd, yyyy HH:MM:SS.FFF AM'))
 m = 2;
 G = gf([
 1 0 0 0 0 1 1;
 0 1 0 0 0 1 2;
 0 0 1 0 1 0 1;
 0 0 0 1 1 0 2
 ], m);

 GConjugated = gf([
 1 0 0 0;
 0 1 0 0;
 0 0 1 0;
 0 0 0 1;
 0 0 1 1;
 1 1 0 0;
 1 3 1 3
 ], m);

 GTimesGConj = gf([
 1 2 1 3;
 3 1 2 1;
 1 3 1 2;
 2 1 3 1
 ], m);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 GMatlab = G;
 GConjugatedMatlab = transpose(GMatlab).^2;
 GTimesGConjMatlab = GMatlab * GConjugatedMatlab;
 detThesis = 1;
 detMatlab = det(GTimesGConjMatlab);
 if ~isequal(GTimesGConj, GTimesGConjMatlab)
        disp("Matlab conjugation didn't match the thesis's.")
 end
 if ~isequal(detThesis, detMatlab.x)
        disp("Determinant didn't match.")
 end
 if isequal(detThesis, 0)
        disp("Thesis determinant is zero.")
 end
 if isequal(detMatlab.x, 0)
        disp("Matlab determinant is zero.")
 end
 if ~isequal(rank(G), size(G, 1)) % size(G, 1) is number of rows in matrix
        disp("The rank of G is not full.")
 end

 fprintf("Run ended %s\n\n", datestr(now,'mmmm dd, yyyy HH:MM:SS.FFF AM'))
 beep
 totalTime = seconds(toc);
 totalTime.Format = 'hh:mm:ss.SSS';
 fprintf('Total time elapsed: %s\n', char(totalTime));
Since:
1.8
Version:
1.0 (January 26th, 2022)
Author:
Maysara Al Jumaily
  • Constructor Details

    • MatlabCodeWriter

      public MatlabCodeWriter(DirectoryCreator dc, CodeParameters cp, Matrix matrix, String id, boolean printPathToConsole)
      Initializes the Matlab code writer based on the parameters specified.
      Parameters:
      dc - the directory creator object to ensure the files are stored in the appropriate place
      cp - the code parameters (i.e., \(n\), \(k\), \(d\), \(base\), etc.)
      matrix - the generator matrix \(G\)
      id - The id that would be associated with the matrix. Used when multiple generator matrices of the same \(\left[n, \, k, \, d\right]_{base}\) code are generated. Should be "0" if only a single generator matrix is found.
      printPathToConsole - should the file paths generated be printed to console
  • Method Details

    • writeCodeToFile

      public void writeCodeToFile()
      Writes the .m file to path passed into the constructor without creating a new folder.