MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

0

plot too many lines

Elias de Korte さんによって質問されました 2019 年 2 月 4 日
最新アクティビティ Elias de Korte さんによって コメントされました 2019 年 2 月 5 日
Why does MATLAB plot so many dashed lines when I am plotting just one for the 95% confidence intervals?
xd = bindex_total2_nonan(:,9); % depth
yd = bindex_total2_nonan(:,6); % pos
% poly fit
[pd,Sd] = polyfit(xd,yd,1);
[y_fitd,deltad] = polyval(pd,xd,Sd);
conf1 = y_fitd+2.*deltad;
conf2 = y_fitd-2.*deltad;
figure('Renderer', 'painters', 'Position', [10 10 900 600]);
scatter(bindex_total2(:,9),bindex_total2(:,6),'+','k');
hold on;
plot(xd,y_fitd,'color','k')
plot(xd(1:2:54),conf1(1:2:54),'r--')
plot(xd(1:2:54),conf2(1:2:54),'r--')

  6 件のコメント

Elias de Korte 2019 年 2 月 4 日
deltad, xd and y_fitd are both 54x 1 vectors, but I think it has something do do with these double values in the deltad output
deltad =
25.9672
25.9672
25.9672
25.4818
25.4818
25.7058
25.7058
25.7416
25.7416
25.3641
25.3641
25.3641
etc.
YT
2019 年 2 月 4 日
I was also looking at this problem, and if it's not the dimensions of xd/yfit that causes the problem maybe its indeed like @Walter Roberson suggested. Also maybe its a good practice to close figures (close all;) and clear workspace variables (clear;) at the start of the script.
Elias de Korte 2019 年 2 月 4 日
I have used clear and close all for every run and this does not solve the problem. I have added hold off as wel, without result

サインイン to comment.

2 件の回答

Walter Roberson
回答者: Walter Roberson
2019 年 2 月 4 日
 採用された回答

Try
xu = unique(xd); %unique and sorted
[y_fitd,deltad] = polyval(pd,xu,Sd);
and then
plot(xu, y_fitd, 'color','k');
I suspect that you will not need to skip every second point for the other plots.

  2 件のコメント

Elias de Korte 2019 年 2 月 5 日
yes, unique values solves the problem visually. But the problem is this:
for x- values i have 54 unique values, for example values concerning 3 months within the year. For the other y-variable i have only got yearly values, which is why some of the same y-values are assigned to different x-values. The solution would be to average the x-values for each year I guess.
Elias de Korte 2019 年 2 月 5 日
Now i expected a linear confidence interval, but this is not the case. I can't find how to change the settings correctly

サインイン to comment.


Rik
回答者: Rik
2019 年 2 月 4 日

You should not use clear on its own. If you want to, you can use
clear variables
As to your actual problem, is your xd not sorted? That would cause the line to jump back and forth, making it look like you have a lot of different lines.

  3 件のコメント

YT
2019 年 2 月 4 日
Can you clarify why "you should not use clear on its own"? Isnt typing every specific variable you want to clear from your workspace much more troublesome than just using clear;?
Rik
2019 年 2 月 4 日
Maybe I worded it a bit too strongly, but when people read the advice to use clear, they will often understand it to use this
clc,close all,clear all
This means that not just the variables are cleared, but also loaded functions and clases, slowing code down. You can read the options in the doc for clear.
Literally typing
clear variables
seems to do the same as only using clear, but this way you show your intent as well preventing misunderstandings.
Also, you can use wildcards and/or regular expressions to specify groups of variables you might want to clear.
YT
2019 年 2 月 4 日
Ah okay good to know. Thanks for the clarification.

サインイン to comment.



Translated by