Info
此问题已关闭。 请重新打开它进行编辑或回答。
How can i acess to created objects out of the class
1 次查看(过去 30 天)
显示 更早的评论
Hello. I have a simple Class:
classdef Packung
properties
preis
menge
l
end
methods
function this = Packung(p,m,l)
this.preis = 0;
this.menge = 0;
this.l=l;
%this = this.setPreisMenge(p,m);
end
function this = setPreisEinkaufswagen(this, p)
xxx = this.preis;
display(xxx);
% Objekt2 = setPreisMenge(Objekt2, 2, p);
end
function [this,objekt] = setPreisMenge(this,objekt, p,m)
this.preis = p;
this.menge = m;
objekt.preis = objekt.preis + 100;
end
end
end
now i have another function, in which i want to make a for loop, going through all the objects created from my Class Packung. How to do this?
I tired following: Function PriceProducts is NOT in the Class. Before i started the Function, i made a object from the class: Milch = Packung (1,2,3)
function PriceProducts()
for i=1:10
Product_buying= Milch;
...
end
Though i get an error, Undefined function or variable 'Milch'.
How to manage this? I'd like to predifine all the Objects that need to be used, and then i want to loop them.
0 个评论
回答(2 个)
Erik S.
2015-2-8
Don't you have to pass the "Milch" variable to the function PriceProducts? I don't see how the function gets this value otherwise?
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!