フィルターのクリア

Unwanted line on graph plot?

7 ビュー (過去 30 日間)
Rahul Pillai
Rahul Pillai 2017 年 9 月 1 日
編集済み: KSSV 2017 年 9 月 1 日
Hello, I was trying to plot a simple code like this:
x=1:6;
y=zeros(6);
for i=1:6
y(i)=2^i;
end
figure(1)
hold on
xlabel('Number of Nodes')
ylabel('Maximum force(N)')
plot(x,y,'-o')
grid on
However, I get this unnecessary line plotted on the x-axis (all points on the x-axis with y coordinate zero) but x coordinates are same as that of the x-coordinates above. How can I remove this ?

回答 (2 件)

Steven Lord
Steven Lord 2017 年 9 月 1 日
You don't want to start with y a 6-by-6 matrix with every element equal to 0. You want to start with a 6 element vector, like:
y = zeros(1, 6);

KSSV
KSSV 2017 年 9 月 1 日
編集済み: KSSV 2017 年 9 月 1 日
x=1:6;
y=zeros(1,6);
for i=1:6
y(i)=2^i;
end
figure(1)
hold on
xlabel('Number of Nodes')
ylabel('Maximum force(N)')
plot(x,y,'-o')
grid on
When you initialize y = zeros(6), it will be a matrix.....don't initialize it as a matrix...initialize it as a vector, y = zeros(1,6) .
You need not to use a loop.....
x=1:6;
i=1:6 ;
y=2.^i;
figure(1)
hold on
xlabel('Number of Nodes')
ylabel('Maximum force(N)')
plot(x,y,'-o')
grid on

カテゴリ

Help Center および File ExchangeVisual Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by