vectors must be the same length

I'm trying to create a graph but the code is getting teh error above.
x = [3.15647 4.15647 5.15647 6.15647 7.15647]; y = [4.15280 5.88409 7.81539 5.24301 4.09266];
plot(x,y,'o'); hold on
xa = linspace(0, 0.5, 10) ya = 4.15+(1.73.*(x-3.15))+(0.1.*(x-3.15).*(x-4.15)); plot(xa,ya,'-');

回答 (2 件)

Star Strider
Star Strider 2018 年 1 月 27 日

0 投票

You probably want to use ‘xa’ rather than ‘x’ in your ‘ya’ calculation:
ya = 4.15+(1.73.*(xa-3.15))+(0.1.*(xa-3.15).*(xa-4.15));
Rik
Rik 2018 年 1 月 27 日

0 投票

You used the variable x in your definition of ya, which results in xa being length 10 and ya being length 5.
x = [3.15647 4.15647 5.15647 6.15647 7.15647];
y = [4.15280 5.88409 7.81539 5.24301 4.09266];
xa = linspace(0, 0.5, 10);
ya = 4.15+(1.73.*(xa-3.15))+(0.1.*(xa-3.15).*(xa-4.15));
plot(x,y,'o',xa,ya,'-')
(Also, next time, select your code and push the {}Code button to correctly format your code)

カテゴリ

ヘルプ センター および File ExchangeDiscrete Data Plots についてさらに検索

質問済み:

2018 年 1 月 27 日

回答済み:

Rik
2018 年 1 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by