Have fimplicit have the axis in the order of the function handle inputs, even when not every variable is used in the expression.
2 次查看(过去 30 天)
显示 更早的评论
I have a function handle that only uses one of the two inputs it has, and the order matters. As of now, fimplicit reads the function, and interprets the only variable used in the expression with the x-axis, resulting in an unwanted plot.
What can I do as to avoid that, and have fimplicit plot in the same order as the input of function handles are defined?
Here is the code:
my_function = @(x,y) y
fimplicit(my_function)
This plots a vertical line, as expected of (0=x), but I want an horizontal one as must be with (0=y).
I think it would resolve the issue to have fimplicit read the @(x,y) as: first entry - horizontal axis, and second entry - vertical axis, but that is just an idea. I'm looking forward on your answers.
Have a nice day,
0 个评论
回答(2 个)
Vaibhav
2023-10-19
Hi Antonio,
I understand that you would like to plot a horizontal line when you pass the function handle to "fimplicit".
The "fimplicit" function assumes that the first variable in function handle corresponds to the x-axis, and the second variable corresponds to the y-axis. To achieve the desired result one approach can be swapping the order of the variables in the function handle.
Refer to the code snippets below: the first snippet uses y as the first variable and x as the second, while the second snippet has x as the first variable and y as the second.
% Define a function handle with y as the first variable and x as the second
my_function = @(y, x) y;
% Plot the function using fimplicit
fimplicit(my_function);
% Add labels and title for clarity
xlabel('x-axis');
ylabel('y-axis');
title('Desired Horizontal Line');
% Define a function handle with x as the first variable and y as the second
my_function_swapped = @(x, y) y;
% Plot the function using fimplicit
fimplicit(my_function_swapped);
% Add labels and title for clarity
xlabel('x-axis');
ylabel('y-axis');
title('Desired Horizontal Line (Swapped Variables)');
You can refer to below MathWorks documentation to know more about "fimplicit":
Hope this helps!
0 个评论
Walter Roberson
2023-10-19
Your code already plots a horizontal line like you want.
my_function = @(x,y) y
fimplicit(my_function, '-*')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Formatting and Annotation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!