Not able to assign a value to a member of class in MATLAB
Afficher commentaires plus anciens
Below is the class definition and I want to change obj.inputs by using setInputs method:
classdef LinearLayer
%UNTITLED2 Summary of this class goes here
% Detailed explanation goes here
properties
weights = [];
bias = [];
inputs = [];
end
methods
function obj = LinearLayer(weights,bias)
%UNTITLED2 Construct an instance of this class
% Detailed explanation goes here
obj.weights = weights;
obj.bias = bias;
end
function obj = setInputs(obj,inputArg)
obj.inputs = inputArg;
end
function outputArg = forward(obj,inputArg)
%METHOD1 Summary of this method goes here
% Detailed explanation goes here
% obj.setInputs(inputArg);
outputArg = obj.weights*inputArg+obj.bias;
end
function [outputArg,dweight,dbias] = backward(obj,inputArg)
outputArg = inputArg*obj.weights;
dweight = - (inputArg')*(obj.x');
dbias = -inputArg';
end
end
end
The main script is:
weights = [-1,-2,0,1,2;...
-2,-1,1,2,3];
bias = [-1;1];
linearlayer = LinearLayer(weights,bias);
inputs = [1,2,3,4,5]';
linearlayer.setInputs(inputs);
After running the main script, linearlayer.inputs = [] instead of [1;2;3;4;5]
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Construct and Work with Object Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!