Hi Kantemir,
According to the MATLAB documentation, when creating a custom network using the "network" function, it is essential to train the network before utilizing it with the "sim" function. The "sim" function is responsible for simulating the trained network's response to input data. The reason behind this requirement is that the "network" function generates a network object with randomly initialized weights and biases. These initial values are not suitable for producing accurate predictions or classifications. Consequently, prior to employing the network for a specific task, it is necessary to train it by adjusting the weights and biases based on a training dataset. The training process typically involves iteratively adjusting the network's weights and biases in response to the error between the desired output and the predicted output. This iterative process enables the network to learn and enhance its performance on the given task. Once the network has undergone proper training, the "sim" function can be used to provide input data and obtain the network's response.
Attempting to use the "sim" function on an untrained network may result in size mismatch errors, as the network's weights and biases have not been adjusted to align with the specific task or dataset. Therefore, it is crucial to train the network prior to utilizing the "sim" function, ensuring that accurate predictions or classifications can be made.
You can refer to the below MathWorks documentation for more information:
On "network" function:
On "sim" function:
Hope this helps!