A method to measure the complex permittivity and permeability of a sample of isotropic material partially filling the rectangular waveguide cross section is presented. The method is based on a multimodal analysis of the waveguide and it does not imply any restriction on the general use of this technique for different widths, lengths or location of the samples. Electromagnetic properties of the material are determined by matching the S-parameters measured with a vector network analyser and the S-parameters calculated theoretically. Convergence to the correct solution is ensured using an optimization technique based on nonlinear minimization. A comparison between theoretical and experimental measurements is realized, which shows the feasibility of the implemented software. Besides, the accurate determination of the properties of the well-known materials validates the performance of the measurement method. Also, an error analysis is performed which confirms the reliability and robustness of our method.