Invalid expression error even though the code seems to be correct
12 次查看(过去 30 天)
显示 更早的评论
this is the code I am trying to run is similar to this
classdef MyParameters
properties
param1
param2
param3
param4
param5
param6
param7
param8
param9
param10
param11
end
methods
function obj = MyParameters(params)
obj.param1 = params(1);
obj.param2 = params(2);
obj.param3 = params(3);
obj.param4 = params(4);
obj.param5 = params(5);
obj.param6 = params(6);
obj.param7 = params(7);
obj.param8 = params(8);
obj.param9 = params(9);
obj.param10 = params(10);
obj.param11 = params(11);
end
end
end
paramsArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
myParams = MyParameters(paramsArray);
I keeep getting the following error message
Error using Tail_Design
File: Tail_Design.m Line: 33 Column: 1
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use
brackets instead of parentheses.
It highlights the array definition (paramsArray) as the error
0 个评论
回答(1 个)
Cris LaPierre
2023-5-22
编辑:Cris LaPierre
2023-5-22
It appears you may not understand how to use the code you have shared.
Your classdef code needs to go in it's own m-file (lines 1-31). Save this file with the same name as your class. Then, in a separate script, use the last 2 lines of code you shared to instantiate your class.
paramsArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
myParams = MyParameters(paramsArray)
2 个评论
Cris LaPierre
2023-5-22
If you want a quick introduction to OOP in MATLAB, I recommend going through the Object-Oreinted Programming Onramp. It's free, interactive, let's you go at your own pace, and takes about 2 hours to complete.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!