フィルターのクリア

Want to remove a line in my plot

27 ビュー (過去 30 日間)
Grace
Grace 2021 年 12 月 15 日
コメント済み: Star Strider 2021 年 12 月 18 日
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

採用された回答

Star Strider
Star Strider 2021 年 12 月 15 日
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 件のコメント
Grace
Grace 2021 年 12 月 18 日
Hi, Star.... Thank you very much
Star Strider
Star Strider 2021 年 12 月 18 日
As always, my pleasure!
.

サインインしてコメントする。

その他の回答 (1 件)

Voss
Voss 2021 年 12 月 15 日
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 件のコメント
Grace
Grace 2021 年 12 月 16 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by