I entered the following:
for s=1:ns
if s=1
y=1
else y=theta
end
and received the following error:
Error: File: hw1a.m Line: 16 Column: 17 The expression to the left of the equals sign is not a valid target for an assignment.
Line 16 is "if s=1" I do not understand the meaning of this error.
thank you for your help,
drew

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 2 月 16 日
編集済み: Azzi Abdelmalek 2014 年 2 月 16 日

1 投票

ns=10
theta=100
for s=1:ns
if s==1
y=1
else
y=theta
end
end
Image Analyst
Image Analyst 2014 年 2 月 16 日
編集済み: Image Analyst 2014 年 2 月 16 日

1 投票

You need to use double equals s==1, and you're missing an "end". But really, you should take the y assignment out of the loop and do it like this:
y = 1;
for s = 1 : ns
y=theta
end
It's more efficient because you're not having to do the "if" test. Presumably theta changes somewhere inside the loop that is just not shown.

カテゴリ

ヘルプ センター および File ExchangeDebugging and Improving Code についてさらに検索

質問済み:

2014 年 2 月 16 日

編集済み:

2014 年 2 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by