Getting "Error: This statement is incomplete."

Hello. This is my code and I keep getting the error "This statement is incomplete." several times throughout but can't find the mistake.
6
figure (6);
v1 = [1 0 -5 0 0 4];
k=1;
for i=[-3 : 0.2 : 3]
p1 (k) = polyval(v1,i);
k = k+1;
j=1;
for i=[-3 : 0.2 : 3]
if i >= 0
v2 (j) = i^3;
j = j+1;
else if i < 0
v2 (j) = i^3 * (-1);
j = j+1;
end
end
end
plot (p1); grid on; hold on;
plot (v2);
Here's the errors:

4 件のコメント

KSSV
KSSV 2018 年 4 月 9 日
The given code works fine.......is there any code before figure(6)?
The Canary Cry
The Canary Cry 2018 年 4 月 9 日
Yes, but I've also tried copying it into its own .m file in which case I only get the last two errors.
KSSV
KSSV 2018 年 4 月 9 日
Error could be the previous lines...the given lines work fine.
The Canary Cry
The Canary Cry 2018 年 4 月 9 日
It gives me the same errors when it's just these lines as well

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

回答 (2 件)

Walter Roberson
Walter Roberson 2018 年 4 月 9 日

1 投票

There is no end for the first for loop. You start a second for i without an end for the first.

1 件のコメント

The Canary Cry
The Canary Cry 2018 年 4 月 9 日
Oh, thank you! That solved it.

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

Birdman
Birdman 2018 年 4 月 9 日
編集済み: Birdman 2018 年 4 月 9 日

0 投票

You seem to be missing end of the first for loop. Use this simplified code:
figure;
v1 = [1 0 -5 0 0 4];
i=-3:0.2:3;
p1 = polyval(v1,i);
v2=zeros(1,numel(i));
v2(i>=0) = i(i>=0).^3;
v2(i<0) = i(i<0).^3 *(-1);
plot (p1); grid on; hold on;
plot (v2);

カテゴリ

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

タグ

質問済み:

2018 年 4 月 9 日

編集済み:

2018 年 4 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by