Warning: Negative data ignored
Mostrar comentarios más antiguos
Hi, I am trying to plot multiple plots of different ions, For example,column ion(mean values of ion density), mid (another column) and err(std dev of ion density). Some value are NaN but none negative. I have changed NaN to 0 yet I get an error in the tile "Warning: Negative data ignored" on title or on figure() of the next plot. Please find my prog below:
....................................................................................................................
ion(isnan(ion))=0;
err(isnan(err))=0;
figure()
semilogx((ion),mid,'.g',LineStyle='none',LineWidth=1.5,MarkerSize= 8 )
text(ion(1), 160,'\rightarrow Ion^+','Color','green','Rotation',-90,'FontSize',10)
hold on
errorbar(ion,mid,err,'horizontal',LineStyle='none', Color='g',LineWidth = 0.1,CapSize=2)
grid on
xlabel('Ion')
ylabel('Mid')
xlim([0.005 50])
ylim([80 500])
title('density' ,FontSize=10)
hold off
....................................................................................................................
link to prog and data: https://drive.google.com/drive/folders/111PwK1cC-09H_Pm7aHTJItMKhTaELyb2?usp=drive_link
2 comentarios
Shivam
el 20 de En. de 2024
Hi,
Could you attach the data files using the paperclip icon so I can investigate the issue?
Sonali
el 20 de En. de 2024
Editada: Walter Roberson
el 21 de En. de 2024
Respuesta aceptada
Más respuestas (2)
I believe the error message is technically incomplete. It should probably say something like "Negative and zero data ignored" when you're plotting data that includes either negative numbers or 0 on a log scale.
x = log(0)
Where exactly should this x be plotted on a logarithmic X axis? Do you have an infinitely wide monitor on which to display this point?
If you have X data that is negative or 0 in your data, you need to replace it with a positive number in order to show it on a semilogx axes.
Note that log() of a negative number can't be plotted that is correct. If you want to show their abs values in different color, e.g.:
x = randi([-2 6], 1, 50);
y = sin(x);
% Separation of negative and positive values of x
IDX1 = x>=0;
IDX2 = x<0;
xpos=x(IDX1);
y_xpos = y(IDX1);
xneg = x(IDX2);
y_xneg = y(IDX2);
figure()
semilogx(xpos,y_xpos,'.g','LineStyle','none','LineWidth',1.5,'MarkerSize',10, 'DisplayName', 'x >=0')
hold on
semilogx(abs(xneg),y_xneg,'pr','LineStyle','none','LineWidth',1.5,'MarkerSize',13, 'DisplayName', 'x < 0')
legend('show')
hold off
figure() % See "Warning: Negative data ignored "
semilogx(x,y,'.g','LineStyle','none','LineWidth',1.5,'MarkerSize',10, 'DisplayName', 'x >=0')
1 comentario
Sonali
el 20 de En. de 2024
Categorías
Más información sobre Graphics Performance en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

