Invalid expression error even though the code seems to be correct

12 vues (au cours des 30 derniers jours)
Kishan C Jolapara
Kishan C Jolapara le 22 Mai 2023
Modifié(e) : Cris LaPierre le 22 Mai 2023
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

Réponses (1)

Cris LaPierre
Cris LaPierre le 22 Mai 2023
Modifié(e) : Cris LaPierre le 22 Mai 2023
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)
myParams =
MyParameters with properties: param1: 1 param2: 2 param3: 3 param4: 4 param5: 5 param6: 6 param7: 7 param8: 8 param9: 9 param10: 10 param11: 11
  2 commentaires
Cris LaPierre
Cris LaPierre le 22 Mai 2023
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.
Kishan C Jolapara
Kishan C Jolapara le 22 Mai 2023
Understood thanks!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Entering Commands dans Help Center et File Exchange

Tags

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by