I'm writing a code using Matlab OO programming. I came across a problem trying to write a method that changes the value of a matrix inside the same object. I've tested my method and it does exactly what I want it to do but it does not save back the results.
Here is my code: Take a look on : function obj = initCC(obj)
%% searchDat picks values for the object properties in a fite %% Importa a função searchDat() %%
classdef methExpl
%Classe de Metodos Explicitos
% Detailed explanation goes here
properties
%Declara Altura da Placa, Largura, Nós em X, Nós em Y, K, Matriz
%com a solução do passo atual, matriz com a solução do passo
%Variáveis Geométricas
%Altura e Largura
Height
Length
%Variáveis da Malha
%Número de nós em X e Número de nós em Y
%Passo de tempo
NodeX
NodeY
timeStep
%Propriedades Físicas
%Condutividade Térmica, Temperatura no Contorno
%Temperatura Inicial uniforme na chapa
kTerm
boundaryTemp
initTemp
%Soluções parciais
%Matriz com a solução da iteração atual
%Matriz com a solução da iteração passada
curMat
lastMat
end
properties (SetAccess = private)
%Arma
funTermMAT
erro = {}
end
methods
function obj = methExpl()
%Construtor da Classe
%Inicializa as variaveis com os valores no arquivo input.dat
%Inicializa a matriz
obj.Height = searchDat('[Height]','input.dat');
obj.Length = searchDat('[Length]','input.dat');
obj.NodeX = searchDat('[NodesX]','input.dat');
obj.NodeY = searchDat('[NodesY]','input.dat');
obj.kTerm = searchDat('[ThermalConductivity]','input.dat');
obj.boundaryTemp = searchDat('[BoundaryTemperature]','input.dat');
obj.initTemp = searchDat('[InitalTemperature]','input.dat');
obj.curMat = zeros(obj.NodeX,obj.NodeY);
%inicializa a matriz com a temperatura do contorno:
obj.initCC();
obj.lastMat = zeros(obj.NodeX,obj.NodeY);
end
function obj = initCC(obj)
%initCC Inicializa a matriz com a condição de contorno de
%temperatura
lim = size(obj.curMat);
for (i =1 : lim(1))
for (j = 1 : lim(2))
if (i==1) || (i == lim(1))
obj.curMat(i,j) = obj.boundaryTemp;
elseif (j==1) || (j ==lim(2))
obj.curMat(i,j) = obj.boundaryTemp
end
end
end
obj.curMat
end
end
end
Before quitting the initCC and get:
ans =
3 3 3 3 3 3 3 3 3 3 3
3 0 0 0 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0 0 0 3
3 3 3 3 3 3 3 3 3 3 3
Which is exactly what I want. If I call it from the outside after initializing it I get:
ans =
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
As if the result of the method I have created has been destroyed.