Borrar filtros
Borrar filtros

Want to remove a line in my plot

27 visualizaciones (últimos 30 días)
Grace
Grace el 15 de Dic. de 2021
Comentada: Star Strider el 18 de Dic. de 2021
Hi, pls I need to remove a straight line in my plot. I attached the two files ('A.txt' and 'B.txt') that I am analyzing. Could someone help out on this;
This is my code;
A=load('A.txt');B=load('B.txt');
X=(B(:,2)-A(:,2))/A(:,2);
plot(A(:,1),X, 'k');xlim([780 820])
Thank you

Respuesta aceptada

Star Strider
Star Strider el 15 de Dic. de 2021
A = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/835480/A.txt');
A = A(:,[2 3]);
B = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/835485/B.txt');
X=(B(:,2)-A(:,2))./A(:,2);
figure
plot(A(:,1),X, 'k');
xlim([780 820])
It is not the same plot, and there is no horizontal line.
Since the data are probably in columns in the original plot as they are here, one option is:
AX = sortrows([A X],1)
A1 = AX(:,1)
X = AX(:,2)
figure
plot(A1, X, 'k');
xlim([780 820])
and see if that works, since it appears that the data are ‘wrapping’, and the sortrows call should eliminate that.
.
  4 comentarios
Grace
Grace el 18 de Dic. de 2021
Hi, Star.... Thank you very much
Star Strider
Star Strider el 18 de Dic. de 2021
As always, my pleasure!
.

Iniciar sesión para comentar.

Más respuestas (1)

Voss
Voss el 15 de Dic. de 2021
You should change the calculation of X to be:
X=(B(:,2)-A(:,2))./A(:,2);
This does element-wise division rather than matrix division.
If you check the size and value of X with the calculation the way you had it, you would see that X was a 2048-by-2048 matrix, so when you plot it against A(:,1), you are actually plotting 2048 lines, all but one of which are all zeros (the flat line).
With element-wise division, X is a column vector and one line is plotted, which is, I believe, what is intended.
  1 comentario
Grace
Grace el 16 de Dic. de 2021
Thank you Benjamin. I think, the element wise operation is best for me because it preserves the shape the shape of my expected result. But by performint the element-wise operation, the true shape of the data is lost.
So, I am still thinking on how to correct this error

Iniciar sesión para comentar.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by