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);