Function that will receive two function handles as input arguments and plot? - Homework
显示 更早的评论
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 个评论
Nora
2013-11-2
编辑:Walter Roberson
2013-11-2
Image Analyst
2013-11-2
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
2013-11-2
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
2013-11-2
Image Analyst
2013-11-2
Did you overlook this in my answer: <http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup???
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!