フィルターのクリア

In an assignment A(:) = B, the number of elements in A and B must be the same.

1 回表示 (過去 30 日間)
Andrew Ghali
Andrew Ghali 2015 年 10 月 12 日
コメント済み: cmptalle 2018 年 1 月 30 日
im trying to graph the sin and cos graph on the same graph and the error that keeps appearing is
"In an assignment A(:) = B, the number of elements in A and B must be the same."
Here is the code that ive put in my script.
x=[0:0.01:2*pi];
y(1)=cos(x);
y(2)=sin(x);
plot(x,y(1),'-k',x,y(2),'--b');

回答 (1 件)

Star Strider
Star Strider 2015 年 10 月 12 日
You’re creating a matrix (which is also good programming practice in this instance), but not quite correctly. To create ‘y(1)’ as the first row, you need to add a column dimension to it, using the colon operator (:) to define it:
x=[0:0.01:2*pi];
y(1,:)=cos(x);
y(2,:)=sin(x);
plot(x,y(1,:),'-k',x,y(2,:),'--b')
This should produce the result you want.
  3 件のコメント
Star Strider
Star Strider 2015 年 10 月 12 日
Please post your code. The code I posted ran without error.
cmptalle
cmptalle 2018 年 1 月 30 日
I've been looking for ages for someone to tell me how to fix this rather than just explaining what the error meant, thank you!

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

カテゴリ

Help Center および File ExchangeDirected Graphs についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by