Since I couldn't find a way to change the frequency of PWM output in MATLAB, I want to write my own function in MATLAB. But I couldn't find a reliable source to get help.
Is there a way to write my own function to control Arduino's output in MATLAB?
It is a microcontroller that has an AVR core with some peripherals.
The PWM pins are done with output compare registers that cause modulation when some control bits are set correctly. Arduino has abstracted this for you into what they call analogWrite()
Now if you want MATLAB (or any Windows/Mac/Linux program) to access those functions you have to write an Arduino program that runs on the ATmega328p and exposes the desired functions in a way that MATLAB can interface (e.g. over the serial port).