Plot array of x ,y both in 2 columns, got unexpected multiple line result.
1 view (last 30 days)
Show older comments
Tamura Kentai
on 19 Jul 2019
Answered: Tamura Kentai
on 19 Jul 2019
Hi, :
I beg your pardon, I got some unexpected result of plot number of line. I have uploaded the .mat files which contained the x,y axes data.
The code is as below:
% plot_array_result_in_multiple_line.m
load('X.mat','X');
load('Y.mat','Y');
plot(log10(X(:,1)),20*log10(hypot(Y(:,1),Y(:,2))));
title( ['Plot Bode']);
xlabel( 'x=Freq-axis (in 10^n)') , ylabel( 'y=data value-axis (in dB)' );
grid on;
But I get 3 lines on the plot figure, as I expect to be only one. One is possible because of the hypot(), root of square , but there is another one (the lowest one) I thought it's very strange, its y-values seems same as reciprocal of x-values, Can anyone know why does it plot this ? And how to fix it ?
Thank you very much.
0 Comments
Accepted Answer
Alex Mcaulley
on 19 Jul 2019
Just one line is ploted. See this:
% plot_array_result_in_multiple_line.m
load('X.mat','X');
load('Y.mat','Y');
h = plot(log10(X(:,1)),20*log10(hypot(Y(:,1),Y(:,2))));
title( ['Plot Bode']);
xlabel( 'x=Freq-axis (in 10^n)') , ylabel( 'y=data value-axis (in dB)' );
grid on;
findobj(h)
ans =
Line with properties:
Color: [0 0.4470 0.7410]
LineStyle: '-'
LineWidth: 0.5000
Marker: 'none'
MarkerSize: 6
MarkerFaceColor: 'none'
XData: [1×3505 double]
YData: [1×3505 double]
ZData: [1×0 double]
Show all properties
The problem is that you have repeated X(1) values (i.e. X(371) == X(1773)), but the corresponding Y are different. For that reason you get "unexpected results".
8 Comments
Alex Mcaulley
on 19 Jul 2019
Sorry, but I don't know what is happening... Just a last try, what is the result of
findobj(gcf)
findall(gcf)
More Answers (1)
See Also
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!