Matlab code not running (no error found)
14 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Torsten
il 10 Feb 2023
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.
Risposte (1)
Suman
il 13 Feb 2023
Modificato: Suman
il 13 Feb 2023
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
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!