problem with str2func
Show older comments
hello I am having a problem using str2func, when matlab says that the function i called to is 'undefined function 'X' for input or arguments of type 'double'.
There is a string which is stored in Shape. Shape gets its string from a function, which gives Shape different values randomly. I have a function for each shape, so for example if Shape gets the value square, there is also a function named square, and i want to call that function according to the string that is stored in Shape.
so i wrote this:
f=str2func(shape);
f(x0,y0);
function [] = vav(x0,y0)
x=[x0 x0+1 x0+1 x0+2 x0+2 x0];
y=[y0 y0 y0+3 y0+3 y0+4 y0+4];
patch(x,y,[0.3 0.2 0.45])
end
so shape gets a string for example shape='vav'; but when i use f=str2func(shape) and i call f(x0,y0) it doesn't work.
how can i fix it? and what is wrong with this way? Thanks!!
Answers (0)
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!