Filter löschen
Filter löschen

Have fimplicit have the axis in the order of the function handle inputs, even when not every variable is used in the expression.

2 Ansichten (letzte 30 Tage)
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
my_function = function_handle with value:
@(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,

Antworten (2)

Vaibhav
Vaibhav am 19 Okt. 2023
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!

Walter Roberson
Walter Roberson am 19 Okt. 2023
Your code already plots a horizontal line like you want.
my_function = @(x,y) y
my_function = function_handle with value:
@(x,y)y
fimplicit(my_function, '-*')

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by