フィルターのクリア

Matlab code not running (no error found)

10 ビュー (過去 30 日間)
roaa zamkah
roaa zamkah 2023 年 2 月 10 日
編集済み: Suman 2023 年 2 月 13 日
I have written the following code that involves multiple loops that returnes vlaues in an array. there is no sytax error, however, results are not obained, I do not know what the problem is because it detects nothing wrong and gives no error message. I know that I can just define one more varible or function to complete this task.
Here is the code:
NSmax=max(NS);
M=0;
E = zeros(NSmax,M);
L = zeros(NSmax,M);
X = zeros(NSmax,M,M,NSmax);
ST = zeros(NSmax,M);
ST1 = zeros(NSmax,M);
h=1;
NS=1;
NS0=0;
NS1=0;
NSmax=0;
while h<=M
m = h;
t = T(m:m,:);
t = t(1:NS(m));
Im = I(m:m, :);
Im = Im(1:NS(m))';
NSh = floor(sum(t)/C(m))+1;
NS0=NS1+NS0;
NS1 = NS(m);
if m ~= 1
np = NP((NS0+1):(NS0+NS1),:);
else
np = NP(1:NS1);
end
a1 = numel(np);
while a1 > 0
a2 = sum(np == 0);
while a2 > 0
b=find(np == 0);
c=b(1,1);
U=Im(b);
i=U(1,1);
z=find(Im == i);
np(c)= [];
Im(z)= [];
stpi=0;
a3=NS0+i;
if NP(a3) > 0
for j=1:NP(a3)
s=P(a3,j);
stpi=stpi+T(h,s);
end
else
stpi=0;
end
E(i,h)=floor((T(h,i)+stpi)/C(h))+1;
%disp(sprintf('E(%d,%d) = %0.0g', i, h, E(i,h)));
stfi=0;
a4=NS0+i;
if NF(a4) > 0
for j=1:NF(a4)
s=F(a4,j);
stfi=stfi+T(h,s);
end
else
stfi = 0;
end
L(i,h) = NSh-floor((T(h,i)+stfi)/C(h));
%disp(sprintf('L(%d,%d) = %0.0f', i, h, L(i,h)));
k=E(i,h);
a5 = X(i,m,h,k);
while a5 ~= 1
ST(k,h) = T(h,i)*X(i,m,h,k)+ST(k,h);
ST1(k,h) = ST(k,h)+T(h,i);
if k <= L(i,h)
if ST1(k,h) <= C(h)
ST(k,h)=ST1(k,h);
X(i,m,h,k)=1;
else
k=k+1;
end
else
NSh = NSh+1;
L(i,h) = k;
if ST1(k,h) <= C(h)
X(i,m,h,k) = 1;
ST(k,h)=ST1(k,h);
L(i,h) = k;
end
end
a5 = X(i,m,h,k);
if a5 == 1
disp(fprintf('E(%d,%d) = %0.0g', i, h, E(i,h)));
disp(fprintf('L(%d,%d) = %0.0f', i, h, L(i,h)));
disp(fprintf('X(%d,%d,%d,%d) = %0.0f', i, m, h, k, X(i,m,h,k)));
disp(fprintf('ST(%d,%d) = %0.0f', k, h, ST(k,h)));
end
end
end
end
end
  8 件のコメント
roaa zamkah
roaa zamkah 2023 年 2 月 10 日
it is a line balancing problem, what i'm trying to achieve is realted to resource allocation, code is a complex using e, l, x, st, st1, and h`, in order to identify the optimal solution. The NSmax variable defines the maximum number of elements that can be allocated to a resource, ns is the number of elements already allocated to a resource, and ns0 and ns1 define the the allocated. loop is through the resources at incrementing The t im` variables and the index of the corresponding element. The nsh variable is used to store the number of resources that can be allocated to the resource. The np array stores the number of resources that a to check if np the resource using and `` variables if enough resources allocate. The stpi and stfi variables are used to store the total number of resources allocated to the element and the number of resources allocated to the resource, respectively. The x variable is used to store the number of resources allocated to a particular element, and the st and st1 variables are used to store the total number of resources allocated to the resource and the total number of resources allocated to the element, respectively. Finally, the disp function is used to display the values of the different variables. This algorithm of allocating resources
Torsten
Torsten 2023 年 2 月 10 日
If you formulate your problem as an optimization problem in a mathematical way and include it here, we might be able to offer a code from the MATLAB software to solve it.
But nobody in this forum will dive into the above code to decipher it, I guess.

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

回答 (1 件)

Suman
Suman 2023 年 2 月 13 日
編集済み: Suman 2023 年 2 月 13 日
Hi Roaa,
It seems there are a few issues with the code that you have provided:
  • In Line-1, the variable "NS" is used, but is declared later in the code. So, either the declaration statement has to be before Line-1 OR maybe it's already there and you haven't provided the full code.
  • In Line-14, the while loop condition "h<=M" will never be satisfied because "h=1" and "M=0" are declared before and h>M.
You can debug the code accordingly as per your requirements.
You may set "Breakpoints" to debug the code and use "Step" functionalility in MATLAB to navigate through the codeflow.
I hope this information is helpful to you.
Cheers,
Suman

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by