Undefined function or variable

I am getting this error even though I have defined the "mat" function in my code. "Undefined function or variable 'mat'." I did some research but I can't find the reason. Because the code is too long, I do not share it all, but I share the relevant part below. other parts of the code are working.
Thanks in advance for your answers.
counter=0;
converg=1;
while converg>0.01;
for j = 2:n-1
min = 1000;
for l = 2:m-1
if number(j,l)~=0 && number(j,l) < min
min = number(j,l);
end
end
for i = 2:m-1
if index(j,i)~=0
n2 = number(j,i);
n1 = n2 - min +1;
if n1 == 1
mat(n1,n1) = C(j,i);
mat(n1,n1+1) = E(j,i);
d(n1,1) = (-1) * (P(j-1,i) * N(j,i)+P(j+1,i)*S(j,i))+Q(j,i);
end
if n1 == max(number(j,:)) - min +1
mat(n1,n1) = C(j,i);
mat(n1,n1-1) = W(j,i);
d(n1,1) = (-1) * (P(j-1,i) * N(j,i)+P(j+1,i)*S(j,i))+Q(j,i);
end
if n1~=1 && n1 ~= max(number(j,:))-min+1
mat(n1,n1) = C(j,i);
mat(n1,n1-1) = W(j,i);
mat(n1,n1+1) = E(j,i);
d(n1,1) = (-1) * (P(j-1,i) * N(j,i)+P(j+1,i)*S(j,i))+Q(j,i);
end
end
end
Pwf = thm(mat,d);
for i = 2:m-1
if index(j,i)~=0
n2 = number(j,i);
n1 = n2 - min +1;
P(j,i) = Pwf(n1,1);
end
end
clear Ps
clear mat
clear d
end
Pdiff = abs(Pold - P);
converg = max(max(Pdiff));
Pold = P;
counter = counter + 1
end

5 件のコメント

Star Strider
Star Strider 2021 年 1 月 10 日
The error (that should have been part of the orignal post) is:
Unrecognized function or variable 'n'.
referring to:
for j = 2:n-1
The obvious solution is to define ‘n’ (as an integer greater than 2) prior to the while loop.
If the error refers to the ‘mat’ variable (I dio not see a ‘mat’ function defined anywhere), note that it is possible that it might not be assigned if the if blocks prevent that assignment because the relevant conditions are not met.
muharrem çevik
muharrem çevik 2021 年 1 月 10 日
I have previously defined 'n' as an integer greater than 2. I redefined the mat function to see the error, but the code started giving other errors. I think I have a bigger problem :)
I'm trying to solve a 2D grid system. I had solved a system with this code before, but it failed in that. I think there is an error in my grid system.
Thank you very much for your reply.
Star Strider
Star Strider 2021 年 1 月 10 日
My pleasure.
Supply the missing ingredients and you may get a useful response.
Walter Roberson
Walter Roberson 2021 年 1 月 10 日
min = number(j,l);
We recommend against using min or max as the names of variables, as it is very common to find that later in the same function one wants to use the min() or max() function. It also confuses readers, who would have to look carefully at the flow of code
muharrem çevik
muharrem çevik 2021 年 1 月 11 日
Thank you. I will consider.

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with Simulink についてさらに検索

質問済み:

2021 年 1 月 10 日

コメント済み:

2021 年 1 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by