how to cut a curve so the y value doesn't go below a ertain number in matlab and the x value also stops in matlab

To cut a curve in MATLAB so that the y values don't go below a certain number and the x values stop, you can use conditional statements to filter and modify the data.

Here's an example of how you can achieve this:

main.m
% Sample curve data
x = linspace(0, 10, 100); % Example x values
y = sin(x); % Example y values

% Specify the threshold for the minimum y value
yMinThreshold = -0.5;

% Filter the data to remove y values below the threshold
xFiltered = x(y >= yMinThreshold);
yFiltered = y(y >= yMinThreshold);

% Plot the original curve and the filtered curve
figure
plot(x, y, 'b-', 'LineWidth', 2) % Original curve is plotted in blue
hold on
plot(xFiltered, yFiltered, 'r-', 'LineWidth', 2) % Filtered curve is plotted in red

% Set a grid and labels
grid on
xlabel('x')
ylabel('y')

% Set the y-axis limits to include the threshold value
ylim([yMinThreshold, max(y)])

% Add a horizontal line at the threshold value
line(xlim, [yMinThreshold, yMinThreshold], 'Color', 'k', 'LineStyle', '--')

% Add a legend
legend('Original Curve', 'Filtered curve')

% Optional: Adjust the x-axis limits if needed
xlim([min(x), max(xFiltered)])
918 chars
34 lines

In this example, the x and y variables represent your original curve data. By specifying a yMinThreshold, the code filters the data and creates new filtered xFiltered and yFiltered variables that exclude the y values that are below the specified threshold. The filtered curve is then plotted together with the original curve, and the y-axis limits are set to include the threshold value. Optionally, you can adjust the x-axis limits if needed.

Note that this is just one way to achieve the desired result, and the specific implementation may vary depending on your specific requirements.

related categories

gistlibby LogSnag