MATLAB Excel Builder    

Illustration 6: myprimes Macro

In this illustration the macro myprimes calls the function myprimes.m with an initial value of 10 in cell A42. The function returns all the prime numbers less than 10 to cells B42 through E42.

Figure 4-13: myprimes Macro

To execute the macro, from the main Excel window (not the Visual Basic Editor), display the Macro dialog either by selecting the Alt and F8 keys at the same time or by selecting the Macros option from Tools -> Macro.

Select myprimes from the list and click Run.

Figure 4-14: myprimes Output for Value of 10

This function automatically resizes if the returned output is larger than the output range specified. Change the value in cell A42 to a number larger than 10. Then rerun the macro. The output returns all prime numbers less than the number you entered in cell A42.

Figure 4-15: myprimes Output for Value > 10


  Illustration 5: Calling mysum Four Different Ways Inspecting the Visual Basic Code