Parse error at EDD

조회 수: 1 (최근 30일)
Rono  Noah
Rono Noah 2020년 11월 17일
답변: Steven Lord 2020년 11월 18일
  댓글 수: 5
Steven Lord
Steven Lord 2020년 11월 18일
Please post it here so everyone can see it and contribute to determining the cause of the error and how to correct it.
Rono  Noah
Rono Noah 2020년 11월 18일
% calculate isotherm of temperature if 1
% define integration parameters
gu
UpLimit_miu = 300;
N_miu = 10;
miu = linspace(0, UpLimit_miu,N_miu*UpLimit_miu);
miu = miu + 0.01;
d_miu = miu(2)-miu(1);
% Initialize the integration matrix
Pe = 0:0.1:7;
L_Pe = length(Pe);
I_miu = zeros(L_Z, L_Pe);
%Sweep through Z
for m = 1:L_Z
for n = 1:L_Pe
H = (Pe(n)*miu.^2).^2./(1+miu.^2)/2+Z(m)^2./miu.^2/2;
y_miu = exp(-H)./(1+miu.^2)/sqrt(2*pi^3);
% y_miu = exp(-(X(n)+Pe(1)*miu).^2./(1+miu.^2)/2)./(1+miu.^2)/sqrt(2*pi^3);
I_miu(m,n) = sum(y_miu)*d_miu;
plot(Pe',I_miu);
drawnow;
end
end
xlabel('Pe')
ylabel('f')
legend('Z/R = 0', 'Z/R = 0.2', 'Z/R = 0.5', 'Z/R = 1')
end

댓글을 달려면 로그인하십시오.

답변 (1개)

Steven Lord
Steven Lord 2020년 11월 18일
Let's look at one section of the snippet of code you posted.
for m = 1:L_Z
for n = 1:L_Pe
H = (Pe(n)*miu.^2).^2./(1+miu.^2)/2+Z(m)^2./miu.^2/2;
y_miu = exp(-H)./(1+miu.^2)/sqrt(2*pi^3);
% y_miu = exp(-(X(n)+Pe(1)*miu).^2./(1+miu.^2)/2)./(1+miu.^2)/sqrt(2*pi^3);
I_miu(m,n) = sum(y_miu)*d_miu;
plot(Pe',I_miu);
drawnow;
end
This end statement ends the for loop using the variable n.
end
This end statement ends the for loop using the variable m.
xlabel('Pe')
ylabel('f')
legend('Z/R = 0', 'Z/R = 0.2', 'Z/R = 0.5', 'Z/R = 1')
end
This end statement either ends something (another for loop, a while loop, a function statement) that began before the start of the snippet you posted or it isn't associated with another keyword. One way to tell which is which is to move the cursor over that end statement. If it is associated with something higher up in the code that should flash on the screen. If it doesn't it's likely a mismatched end.
I'd probably smart indent the code and make sure that each end is associate with the correct statement then remove the extra mismatched one. Which one you remove can make a difference. Consider the following:
function y = foo650718
y = 0;
for k = 1:5
for p = 1:7
y = y + 1;
end
y = y + 1;
end
y = y + 1;
end
end
There are three keywords that start a block to be ended by end: the function statement, the for over k, and the for over p. If you smart indent this (or look at the file in the Editor) there's one extra end statement. But which one you delete (or comment out) will affect the output of the function (except the last two; deleting either of those gives the same result.) Commenting out the first results in y = 75, the second in y = 45, and the third or fourth in y = 41. Smart indenting the code while different end statements are commented out will also show that the various "y = y + 1;" statements get included in different numbers of nested loops depending on which end is commented.

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by