I am getting parse error for this following simple program

5 ビュー (過去 30 日間)
Md Jonayet
Md Jonayet 2023 年 3 月 15 日
コメント済み: Md Jonayet 2023 年 3 月 15 日
y = 1:3; %parse error at y. It is maybe an invalid mathlab syntax
secondar =[ 3 0 -1] ;
unname = polyfit(y, secondar, 1)
unname = 1×2
-2.0000 4.6667
function obiick = solve1(x)
obiick = x^3+x+8 ;
end
Output
solve1(2)
Error: File: solve1.m Line: 6 Column: 1
This statement is not inside any function.
(It follows the END that terminates the definition of the function "solve1".)
  4 件のコメント
Les Beckham
Les Beckham 2023 年 3 月 15 日
編集済み: Les Beckham 2023 年 3 月 15 日
If this is an excerpt from a larger block of code, the error is probably above the first line of code that you posted, since the code you posted does not cause any errors. Oftentimes an incomplete code construct will trigger an error on a line of code that isn't the error but, rather, the first place that the Matlab parser figures out that it can't understand the code and parse it correctly. Please post the complete block of code and, as Matt J suggests, show us the complete error message -- preferably by running your code by clicking the green run button.
Md Jonayet
Md Jonayet 2023 年 3 月 15 日
I updated the code

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

回答 (1 件)

Steven Lord
Steven Lord 2023 年 3 月 15 日
Please show us the full and exact text of the warning and/or error messages you receive (all the text displayed in orange and/or red in the Command Window.) The exact text, not a paraphrased version, may be useful in determining what's going on and how to avoid the warning and/or error.
My suspicion is that you opened a parenthesis, square bracket, or curly brace on a previous line but forgot to close it on that line, something along the lines of:
x = {1+1; % Note no } on this line
y = 2;
Unsupported use of the '=' operator. To compare values for equality, use '=='. To specify name-value arguments, check that name is a valid identifier with no surrounding quotes.
  1 件のコメント
Md Jonayet
Md Jonayet 2023 年 3 月 15 日
I updated my post. Hope it would make other clear of my problem.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by