Function that will receive two function handles as input arguments and plot? - Homework
Mostrar comentarios más antiguos
So I am working on this problem:
Write a function that will receive two function handles as input arguments adn will display plots of these functions in two subplots(column-wise) in a single figure window. The function will create an x vector that has 100 random numbers from 1 to 100.
example: if the function is called plot2fnhand
plot2fnhand(@sqrt,@exp)
the first subplot would display the sqrt function, the second would display exp(x) function.
This is what I have for my function so far:
function rfh = plot2fnhand( x, fh1, fh2 )
x = rand(100);
subpot(2,1,1);
y = fh1(x);
plot(x,y);
title(func2str(fh1));
subpot(2,1,2);
y = fh2(x);
plot(x,y);
title(func2str(fh2));
rfh = @testhd;
end
function testhd()
disp('HANDLE PASSING');
end
I keep on getting errors. ????
5 comentarios
Nora
el 2 de Nov. de 2013
Editada: Walter Roberson
el 2 de Nov. de 2013
Image Analyst
el 2 de Nov. de 2013
Doesn't it tell you what they are, in red text? How are you calling this function? What are fh1 and fh2? How did you create those and pass them into this functions? Please give the code for the calling routine also so we can know how to call this function. Also, please read and understand this: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Cedric
el 2 de Nov. de 2013
You make two mistakes I guess. The first is that you plot twice each function (why?), and the second is that you don't call RAND in a correct fashion. The way you do it in the current version of your code creates a 100x100 array of random numbers uniformly distributed on the interval (0,1). Instead, you want a vector of 100 random numbers in the range [1,100] (or maybe (1,100) to make it simpler).
Nora
el 2 de Nov. de 2013
Image Analyst
el 2 de Nov. de 2013
Did you overlook this in my answer: <http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup???
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!