How to correct "Parse" error

233 ビュー (過去 30 日間)
Matt Spalding
Matt Spalding 2019 年 2 月 15 日
移動済み: Steven Lord 2023 年 7 月 11 日
I'm writing a function and recieving a "Parse error at t; usuage might be invalid MATLAB syntax".
My code is;
function height = rocketHeight(t)
height = (2.13*t^2) - (0..0013*t.^4) + (0.000034*t.^4.754);
end
t = 1;
while (height ~=0)
h = rocketHeight(t);
figure
plot(t,h,'o')
t = t+1;
end
The Parse error is occuring at "t = 1;"
Any help would be greatly appreciated.
end
  1 件のコメント
Star Strider
Star Strider 2019 年 2 月 15 日
The Parse error is occuring at "t = 1;"
Probably not.
It is most likely referring to the previous line:
height = (2.13*t^2) - (0..0013*t.^4) + (0.000034*t.^4.754);
and is referring to the two consecutive dots.
However there are other serious problems, not the least of which is calling the function from within the function, that will cause an ‘infinite recursion’ error.
Think this through a bit more carefully.

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

回答 (2 件)

James Tursa
James Tursa 2019 年 2 月 15 日
編集済み: James Tursa 2019 年 2 月 15 日
Don't have your function at the top of this. Put it at the end or in a separate file. E.g.,
t = 1;
while (height ~=0)
h = rocketHeight(t);
figure
plot(t,h,'o')
t = t+1;
end
function height = rocketHeight(t)
height = (2.13*t^2) - (0.0013*t.^4) + (0.000034*t.^4.754);
end
Or have the function code in a separate file called rocketHeight.m
Also, you are using two different variable names h and height for the same thing. Pick one of those names and use it consistently.
Finally, I am guessing you want to plot the curve of the rocket path. What you have only plots a single point. You need to store all of the t and h values in vectors within the loop, and then plot these vectors once after the loop ends.

Savira
Savira 2023 年 7 月 11 日
編集済み: Savira 2023 年 7 月 11 日
I get Parse error at ')': usage might be invalid to MATLAB syntax when I want to run testing data CNN using pretrained squeezenet,
my coding is like this
Import Data
Import training and validation data.
imdsTrain = imageDatastore("C:\Users\Sxx\OneDrive\Documents\Bxx\Mxx","IncludeSubfolders",true,"LabelSource","foldernames");
datacoba1 = imageDatastore("C:\Users\Sxx\OneDrive\Documents\Bxx\Mxx\TESTING\Ixx Dxx","IncludeSubfolders",true,"Labelso0urce","foldernames");
datacoba2 = imageDatastore("C:\Users\Sxx\OneDrive\Documents\Bxx\Mxx\TESTING\Ixx Dxx","IncludeSubfolders",true,"Labelso0urce","foldernames");
datacoba3 = imageDatastore("C:\Users\Sxx\OneDrive\Documents\Bxx\Mxx\TESTING\Ixx Dxx","IncludeSubfolders",true,"Labelso0urce","foldernames");
datacoba4 = imageDatastore("C:\Users\Sxx\OneDrive\Documents\Bxx\Mxx\TESTING\Ixx Dxx","IncludeSubfolders",true,"Labelso0urce","foldernames");
[imdsTrain, imdsValidation] = splitEachLabel(imdsTrain,0.7);
% Resize the images to match the network input layer.
augimdsTrain = augmentedImageDatastore([227 227 3],imdsTrain);
augimdsValidation = augmentedImageDatastore([227 227],imdsValidation);
datacobatrain1=augmentedImageDatastore([227 227 3]),datacoba1);
datacobatrain2=augmentedImageDatastore([227 227 3]),datacoba2);
datacobatrain3=augmentedImageDatastore([227 227 3]),datacoba3);
datacobatrain4=augmentedImageDatastore([227 227 3]),datacoba4);
I'm still a beginner and I dont know what the error and how to solve it,
I copy this code from a friend
datacobatrain1=augmentedImageDatastore([227 227 3]),datacoba1);
datacobatrain2=augmentedImageDatastore([227 227 3]),datacoba2);
datacobatrain3=augmentedImageDatastore([227 227 3]),datacoba3);
datacobatrain4=augmentedImageDatastore([227 227 3]),datacoba4);
he can run his testing data using that code while mine getting error in that 4 line coding, please if anyone know what could go wrong and how to solve this
  1 件のコメント
Steven Lord
Steven Lord 2023 年 7 月 11 日
移動済み: Steven Lord 2023 年 7 月 11 日
Count the parentheses. Start at 0 at the start of the line. Whenever you see ( add 1. Whenever you see ) subtract 1.
There are two possible errors:
  1. If you would ever reach -1, stop. You have too many closing parentheses or a closing parentheses in the wrong place.
  2. If you don't return to 0 at the end of the statement, you have too many open parentheses.
For your code:
datacobatrain1=augmentedImageDatastore([227 227 3]),datacoba1);
% 0 1 0 X
The X is a -1. You have two closing parentheses but only one opening parenthesis.
You probably want to remove the one immediately after [227 227 3]. If you do:
datacobatrain1=augmentedImageDatastore([227 227 3],datacoba1);
% 0 1 0
No negatives and you got back to 0 at the end of the statement.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by