Skip to main content

Objective:

Learn how to run your nTop notebook using nTop Automate (ntopcl) in Matlab scripts.

Procedure:

  • Prepare the nTop notebook and JSON input for running nTop Automate
  • Matlab Struct data structure can read, modify and write JSON input files.
  • Run (F5)!
  • Check if the return messages are printed as below.
[info] Logging Engine started
[info] Login successful[info] Parasolid started
[info] Parasolid started
[info] nTop successfully built.
[info] Logout successful
Feel free to change this script to batch-process your workflow by passing input lists in a loop!
clc,clear,close all

%Provide file paths to nTopCL, nTop file, and output JSON file
%Assuming input and output JSON files as well as .ntop file in the same folder
pathToExe = ['"' 'C:\\Program Files\\nTopology\\nTopology\\ntopcl.exe' '"'];
FileToRun='SampleFile.ntop';
OutputFile='output.json';

%Provide a input JSON file
InputFile='input.json';
Inputs = jsondecode(fileread(InputFile));

%Modify input variables
Inputs(1).inputs{2,1}.values = 5;
Inputs(1).inputs{3,1}.values = 3;
Inputs(1).inputs{4,1}.values = 2;

%Write JSON file
JsonStr = jsonencode(Inputs);
JsonStr = strrep(JsonStr, ',', sprintf(',\r'));
JsonStr = strrep(JsonStr, '[{', sprintf('[\r{\r'));
JsonStr = strrep(JsonStr, '}]', sprintf('\r}\r]'));
fid = fopen(InputFile, 'w');
if fid == -1, error('Cannot create JSON file'); end
fwrite(fid, JsonStr, 'char');
fclose(fid);

%Compose a execution command
Arguments=sprintf('%s -j %s -o %s %s', pathToExe,InputFile,OutputFile,FileToRun);
%Run
system(Arguments);
And that’s it! You’ve successfully run nTop Automate using Matlab scripts. Are you still having issues? Contact the support team, and we’ll be happy to help!

Download the Example file:

More on this topic: