I don't understand why i keep getting : Error using plot vector must be the same length.
As the data shows s1= 1X100and s2=1X99 which i don't understand why it has that data.
clc;
sym('x');
s= sin(pi*x);
x= linspace(0,4);
subplot(2,1,1);
plot(x,s);
axis([0 4 -4 4]);
subplot(2,1,2);
s1= diff(s);
plot(x,s1)%Error at this line

 採用された回答

madhan ravi
madhan ravi 2018 年 11 月 16 日
編集済み: madhan ravi 2018 年 11 月 16 日

1 投票

see subs() (link) to better understand
x= linspace(0,4);
s= sin(pi*x);
subplot(2,1,1);
plot(x,s);
axis([0 4 -4 4]);
subplot(2,1,2);
syms x
s1= diff(sin(pi*x),x);
x= linspace(0,4);
plot(x,subs(s1,x))

2 件のコメント

Nam Nguyen
Nam Nguyen 2018 年 11 月 16 日
Thank you
madhan ravi
madhan ravi 2018 年 11 月 16 日
Anytime :)

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

その他の回答 (2 件)

KSSV
KSSV 2018 年 11 月 16 日
編集済み: KSSV 2018 年 11 月 16 日

0 投票

YOu have to substitue the value of x in the sym objects s and s1 using subs. After that it will be converted to double and then you can plot them.
syms x;
s= sin(pi*x);
x= linspace(0,4);
subplot(2,1,1);
sr = subs(s,x) ;
plot(x,sr);
axis([0 4 -4 4]);
subplot(2,1,2);
s1= diff(s);
s1r = subs(s1,x) ;
plot(x,s1r)%Error at this line
KSSV
KSSV 2018 年 11 月 16 日

0 投票

YOu need not to use sums actually. Using syms is useless in your case.
x= linspace(0,4);
s= sin(pi*x);
subplot(2,1,1);
plot(x,s);
axis([0 4 -4 4]);
subplot(2,1,2);
s1= gradient(s);
plot(x,s1)%Error at this line

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2018 年 11 月 16 日

回答済み:

2018 年 11 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by