They comprise students from Universiti Gadjah Mada and from the Indonesian Cultural Institute, according to a statement issued by the Foreign Ministry.
Gunung Merapi, located on the border between Central Jawa and Yogyakarta, erupted for the second time yesterday after the first one on Monday.
The 2,968-meter high volcano, the most active in Indonesia, yesterday spewed out hot volcanic ashes up to 3,500 metres high.
Wisma Putra (the Foreign Ministry) said the Malaysian embassy in Jakarta had also assigned two embassy officials to be with the Malaysian students in Yogyakarta to supervise the situation.
Wisma Putra said that 34 Malaysian students and eight other Malaysian nationals who were at the Sirajol Mukhlasin Religious School, Magelang, Central Jawa, situated near Gunung Merapi had been evacuated to the Surakarta State University in Solo, located 65km from Merapi on Wednesday morning.
The statement said the Foreign Ministry continued to monitor the latest development following the Gunung Merapi eruption as well as the earthquake on the Mentawai Archipelago, West Sumatera.
It said that Foreign Minister Datuk Seri Anifah Aman had officielly sent a letter of condolence to his Indonesian counterpart, Dr R M Marty M Natalegawa on Wednesday expressing Malaysia's sympathy following the two disasters.
Wisma Putra also advised Malaysian nationals in Indonesia, especially those staying in the vicinity of the disaster areas to contact Malaysian diplomatic representatives who were in Jakarta, Medan and Pekanbaru if they needed assistance.