In this paper the main goal is to find the optimal architecture of modular neural networks, which means finding out the optimal number of modules, layers and nodes of the neural network. The fuzzy gravitational search algorithm with dynamic parameter adaptation is used for optimizing the modular neural network in a particular pattern recognition application. The proposed method is applied to medical images in echocardiogram recognition. One of the most common methods for detection and analysis of diseases in the human body, by physicians and specialists, is the use of medical images. Simulation results of the proposed approach in echocardiogram recognition show the advantages of using the fuzzy gravitational search in the optimization of modular neural networks. In this case the proposed approach provides a very good 99.49% echocardiogram recognition rate.