how can I plot multiple y values for single x value?

198 ビュー (過去 30 日間)
Francesca Accetta
Francesca Accetta 2018 年 2 月 21 日
コメント済み: Setsuna Yuuki. 2020 年 12 月 2 日
I have to plot multiple y values for single x value, but in the plot all the values related to x=x1 appears on the same column. The relative y values are related to the same day (x) but to subsequent times. I would like to plot y values related to the same x in different columns just labeling the first value of x. It is possible? Thank you The graph that i found is the following but i don't know how to solve the problem.
  3 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 12 月 2 日
編集済み: KALYAN ACHARJYA 2020 年 12 月 2 日
@Chaman can you more specific please? To plot the data, the lengths of x and y must be the same. If we consider the same x value for all the corresponding y data, the result will be a vertical line (parallel to the y-axis).
Chaman Srivastava
Chaman Srivastava 2020 年 12 月 2 日
@kalyan acharjya Yes indeed it will be a straight line. But my goal is to obtain a regression curve with confidence interval, something like what is shown in the curve attached.
Any leads for this? Thanks

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

回答 (1 件)

Setsuna Yuuki.
Setsuna Yuuki. 2020 年 12 月 2 日
you can try creating a vector of ones and multiplying this by your x values, for example:
y = rand(1,15);
xvalue = 3;
x = xvalue*ones(1,length(y));
scatter(x,y,'LineWidth',3);
  3 件のコメント
Chaman Srivastava
Chaman Srivastava 2020 年 12 月 2 日
Hey Bastian,
Thank you the piece of code. I have tried something like this but plotting a regression using polyfit isn't working. Any leads on that?
Setsuna Yuuki.
Setsuna Yuuki. 2020 年 12 月 2 日
I tried it this way
clearvars;
x = linspace(0,30);
i = 0; j = 1;
comp = 1:3:length(x);
vectorx = zeros(1,length(x));
%Vector with three same x values
for n = 1:length(x)
vectorx(n) = i;
if(n == comp(j))
i = i+1;
j = j+1;
end
end
x = vectorx;
%Random data
y = 0.2+rand(1,length(vectorx));
p = polyfit(x,y,1);
f = polyval(p,x);
figure
plot(x,y,'o',x,f,'-','LineWidth',3)
legend('data','linear fit')
grid on;

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

カテゴリ

Help Center および File ExchangeFinancial Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by