Skip to content

Latest commit

 

History

History
157 lines (99 loc) · 4.6 KB

USING_LOCAL_MODEL_MATLAB.md

File metadata and controls

157 lines (99 loc) · 4.6 KB

📘 How to Use the Simulation Script

This guide explains how to use the provided example script run_model.m, which contains all parts of the simulation workflow. The script includes input generation, calling the executable, and post-processing the output. This documentation serves as a guide to understanding the run_model.m workflow and interpreting its outputs.


🧵 Table of Contents

  1. Introduction
  2. Requirements
  3. Setting Up the Script
  4. Step-by-Step Instructions
  5. Troubleshooting
  6. Conclusion

🔍 Introduction

You will have the run_model.m script available, which consists of the following steps:

  • Input Generation: Creates input data for the simulation
  • Simulation Execution: Calls the executable to run the model
  • Output Processing: Reads and reshapes the output data into the desired format

This guide outlines each step to help you understand the workflow and results.


⚙️ Requirements

  • MATLAB installed
  • model.exe executable in the working folder

📜 Setting Up the Script

  1. Ensure the model.exe executable is located in the same folder as your run_model.m script.
  2. The first time you run the script, you may not have the Y_out.csv file, as it is generated by the executable.
  3. Verify all paths and dependencies are correctly configured in your working directory.

📝 Step-by-Step Instructions


📚 Section 1: Creating Input and Calling the Executable

This part of the run_model.m script generates input data, saves it to a file, and calls the executable.


✅ Step 1: Define Input Parameters

% Define the input vector X_input with the desired values
X_input = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 42];

% Optionally, create a batch of N input vectors (N copies of X_input)
N = 3;
X_input_batch = repmat(X_input, N, 1);  % Matrix of size (N x 9)

✅ Step 2: Save the Input Data to input.txt

writematrix(X_input_batch, 'input.txt', 'Delimiter', ',');
disp('Input data written to input.txt');
  • This file contains the input data needed by the simulation executable.

✅ Step 3: Call the Executable to Run the Simulation

disp('Running simulation executable...');
system('model.exe input.txt');
  • This command calls the executable and passes the input data stored in input.txt.

📚 Section 2: Post-processing the Output

After running the simulation, the run_model.m script processes the generated Y_out.csv file.


✅ Step 1: Load the Output Data

Y_output = readmatrix('Y_out.csv');
disp('Simulation output data loaded.');
  • The Y_out.csv file contains the simulation output, which is read into the matrix Y_output.

✅ Step 2: Extract Sample Indices and Clean Data

% Extract unique sample indices (Column 7 contains sample indices)
sample_indices = unique(Y_output(:, 7));
num_samples = numel(sample_indices);

% Remove the sample index column from the output matrix
Y_output(:, 7) = [];
  • Column 7 contains sample indices, which are extracted and then dropped to clean the output matrix.

✅ Step 3: Reshape the Output Data

% Reshape the output data into the desired 3D format (num_time_steps x num_features x num_samples)
Y_out_reshaped = reshape(Y_output', 6, 60, num_samples);
Y_out_reshaped = permute(Y_out_reshaped, [2, 1, 3]);

✅ Step 4: Example - Access Output Data for Analysis

disp('Output values for the first timestep for all 6 features of sample 3:');
disp(Y_out_reshaped(1, :, 3));

🛠️ Troubleshooting

  • Executable Not Found: Ensure model.exe is in the correct folder or update the path in the system call.
  • Missing Y_out.csv: This file is only generated after running the executable. Run the executable first.
  • File I/O Errors: Ensure you have the necessary read/write permissions in your working directory.

✅ Conclusion

  • The run_model.m script contains the entire workflow of input generation, executing the simulation, and processing the output.
  • You can customize input vectors, batch sizes, etc. as needed for your specific use case.
  • This guide provides a clear understanding of each part of the workflow and how the output data is structured.