Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB str2func help

  1. Jul 12, 2010 #1
    I'm wanting to call a function exactly like this but in a different way:
    [Out1,Out2] = BeginName_MiddleName_EndName(In1,In2);

    Basically what I want to do is call this function as simply and elegantly as possible while defining "MiddleName" separately -- this is because I use the same term "MiddleName" for different functions (e.g. function names: solver_001_compute, figures_001_display, etc... where "MiddleName" is "001").In other words, I am looking to set the middle name, then use it in a function as part of the name of the function (a part of the string). Keep in mind that I have inputs.

    I have one that works (see below), but there should be an easier way to do it -- in two lines (1 to define Case, then the other to operate the function -- eliminating the second line of code below). The problem I face is having inputs in a concatenated str2func string. What is the simplest code for "str2func" with inputs and a pieced together function name such as the one below?

    Case = 'MiddleName';

    funcName = str2func(['BeginName_' Case '_EndName']);
    [Out1,Out2] = funcName(In1,In2);
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted