matlab中self.
时间: 2023-11-13 12:54:26 浏览: 402
在MATLAB中,self是一个指向当前对象的指针,可以用来访问对象的属性和方法。在类的方法中,可以使用self来引用当前对象的属性和方法。
例如,如果有一个类叫做MyClass,其中有一个属性叫做myProperty,可以在类的方法中使用self来访问这个属性:
```
classdef MyClass
properties
myProperty
end
methods
function myMethod(obj)
% 使用self来访问myProperty
disp(self.myProperty);
end
end
end
```
相关问题
转成matlab:self.eta = self.eta_max if kwargs.get('first_iter',False) and not self.linesearch_first: self.eta = kwargs.get('eta_first',1) loss_diff = 1 while loss_diff > 0: loss_diff, temp_embedding, delta = self._linesearch_once( update_embedding_with,grad,calc_loss,loss,**kwargs) if self.eta <= self.eta_min and loss_diff > 0: loss_diff, temp_embedding, delta = self._linesearch_once( update_embedding_with,grad,calc_loss,loss,**kwargs) loss_diff = -1 self.eta *= 2 update_embedding_with(new_embedding=temp_embedding) return delta
self.eta = self.eta_max;
if isfield(kwargs,'first_iter') && kwargs.first_iter && ~self.linesearch_first
self.eta = kwargs.eta_first;
end
loss_diff = 1;
while loss_diff > 0
[loss_diff, temp_embedding, delta] = self._linesearch_once(update_embedding_with,grad,calc_loss,loss,kwargs);
if self.eta <= self.eta_min && loss_diff > 0
[loss_diff, temp_embedding, delta] = self._linesearch_once(update_embedding_with,grad,calc_loss,loss,kwargs);
loss_diff = -1;
end
end
self.eta = self.eta * 2;
update_embedding_with('new_embedding',temp_embedding);
end_return = delta;
将下列代码转换成matlab代码%update(self,iiter,H,Y,eta,loss): %"""Update the trace_var in new iteration""" if iiter <= self.niter_trace+1: self.H[iiter] = H self.Y[iiter] = Y elif iiter >self.niter - self.niter_trace + 1: self.H[self.ltrace+iiter-self.niter-1] = H self.Y[self.ltrace+iiter-self.niter-1] = Y self.etas[iiter] = eta self.loss[iiter] = loss if self.loss[iiter] < self.lmin: self.Yh = Y self.lmin = self.loss[iiter] self.miniter = iiter if not iiter == -1 else self.niter + 1 end end end end
function obj = update(obj, iiter, H, Y, eta, loss)
% Update the trace_var in new iteration
if iiter <= obj.niter_trace + 1
obj.H{iiter} = H;
obj.Y{iiter} = Y;
elseif iiter > obj.niter - obj.niter_trace + 1
obj.H{obj.ltrace + iiter - obj.niter - 1} = H;
obj.Y{obj.ltrace + iiter - obj.niter - 1} = Y;
end
obj.etas(iiter) = eta;
obj.loss(iiter) = loss;
if obj.loss(iiter) < obj.lmin
obj.Yh = Y;
obj.lmin = obj.loss(iiter);
obj.miniter = iiter;
end
end
阅读全文