How to find the closest values (positive and negative) to the line when X is zero?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Valentin Augusto Simbron Mckay
el 26 de En. de 2023
Comentada: Valentin Augusto Simbron Mckay
el 26 de En. de 2023
Hi,
I am trying to find the closest two points (positive and negative) when x is zero, I tried with interp1 and find but it didn't work.
Something similar like the image.
This is my code
Thanks for the help
%Data
load Data
%Create line plot
x = V;
y = J;
%plot(x,y,'b-','LineWidth',5);
plot(x,y,'-o','MarkerIndices',1:19:length(y))
hold on
%Label the axes and add a title
xlabel('Voltage V')
ylabel('density current mA/cm2')
title('J-V curve ')
% Set axis start from origin
axis([-0.06 0.7 -0.001 0.008])
%yDesired = interp1(x,y,0);
%Minimum x value for positive y
%Y line
x1 = [0 0];
y1 = [0 0.1];
line(x1,y1,'Color','red','LineStyle','--')
%X line
x2 = [0 0.7];
y2 = [0 0];
line(x2,y2,'Color','red','LineStyle','--')
%find the value when x=0
y=interp1(x,y,0)
0 comentarios
Respuesta aceptada
Matt J
el 26 de En. de 2023
load Data
%Create line plot
[x,is] = sort(V);
y = J(is);
in=find(x<0,1,'last');
ip=find(x>0,1,'first');
[xn,yn, xp,yp]=deal(x(in),y(in), x(ip), y(ip));
plot(x,y,'.',xn,yn,'o',xp,yp,'o');
axis([-0.0056 0.0059 0.0060 0.0063])
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!