Array Of Object and random number generation

2 ビュー (過去 30 日間)
shawin
shawin 2016 年 11 月 3 日
回答済み: Walter Roberson 2016 年 11 月 5 日
I have a class :
classdef Cells <handle
properties
f;
p=[];
c;
end
end
and inheriting it to another class :
classdef color< ClassInheritanceTest.Cells
properties
cells;
Best_Cells;
Population_Size;
Datadimensions;
upperLimit;
lowerLimit;
end
%%Constructor
methods
function obj = color(varargin)
cells =Cells;
Best_Cells=Cells;
Population_Size =50;
Datadimensions=2;
upperLimit=50;
lowerLimit=-50;
end
%%initializing an object array in Matlab.
Cl(Population_Size)= Cells();
function obj = runColor()
range = upperLimit - lowerLimit;
for i = 1: Population_Size
for j= 1 : Datadimensions
Cl(i).p(j) = rand(50,j).*range + lowerLimit;
end
end
end
end
end
received error :
the expression to the left of the equals sign is not a valid target for an assignment.
Cl(Population_Size)= Cells();
? please, any suggestion ?
  3 件のコメント
per isakson
per isakson 2016 年 11 月 4 日
編集済み: per isakson 2016 年 11 月 4 日
Your code doesn't honor Matlab "OO-syntax"; see Comparison of MATLAB and Other OO Languages
KSSV
KSSV 2016 年 11 月 5 日
編集済み: Walter Roberson 2016 年 11 月 5 日
Cl(Population_Size)= Cells();
Cl(i).p(j) = rand(50,j).*range + lowLimit;
Cl is initialized as a cell and being used as structure.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 11 月 5 日
You are inside your "methods" section but you have
Cl(Population_Size)= Cells();
outside of any "function".

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by