Incorrect use of '=' operator. To assign a value to a variable, use '='. To compare values for equality, use '=='.
조회 수: 168 (최근 30일)
이전 댓글 표시
Asking for help.
ERROR "Incorrect use of '=' operator. To assign a value to a variable, use '='. To compare values for equality, use '=='."
I already followed instruction above but another happened
ERROR 2: Illegal use of reserved keyword "for".
This is my code.
clc;
clear;
%dx/dt=ax-bxy Predator
%dy/dt=-cy+dxy prey
%constants as stated on the problem
a = 1.2;
b = 0.6;
c = 0.8;
d = 0.3;
%Defining the functions
%z[x,y]<=z(1,:)= y z(2,:)=x
f=@(t,z)[ ...
+a*z(2)-b*z(2)*z(1)
-c*z(1)+d*z(2)*z(1)
fx==@(t,x,y) a*x - b*x*y;
fy==@(t,x,y) -c*y + d*x*y;
%Initial Conditions
t(1)=0; %time
% x(1)=2; %predator
% y(1)=1; %prey
z(:,1)=[1,2];
%step size
h = 0.001;
tfinal = 30;
N = 1000;
%Loop
for i=1:N
Update time
t(i+1)=t(i)+h;
%update for z
k1=f(t(i), z(:,i));
k2=f(t(i)+h/2, z(:,i)+h/2*k1);
k3=f(t(i)+h/2, z(:,i)+h/2*k2);
k4=f(t(i)+h, z(:,i)+h *k3);
z(:,i+1)=y(:,i) +h/6*(k1+ 2*k2 +2*k3 +k4);
end
%plotting
figure(1)
clf(1)
plot(t,y(1,:))
hold on
plot(t,y(2,:))
xlabel('Time')
ylabel('Populations')
hold off
Thank you and have a nice day
댓글 수: 0
채택된 답변
Stephen23
2019년 5월 24일
편집: Stephen23
2019년 5월 24일
The actual problem starts on this line:
f=@(t,z)[ ...
because your code is missing the matching ]
Using = was correct.
Note that you should use colon or linspace to generate t, rather than the inefficient method that you use now.
댓글 수: 2
Stephen23
2019년 5월 24일
"How can I revised my code?"
Add the ] at the end of the concatenation.
Change back to =
추가 답변 (2개)
Tareq Rahmani
2020년 3월 23일
what is wrong here :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/278834/image.png)
댓글 수: 1
Stephen23
2020년 3월 23일
@Tareq Rahmani: in MATLAB square brackets are a concatenation operator. What are you concatenating?
Simbarashe Zuva
2021년 12월 24일
편집: Walter Roberson
2021년 12월 24일
I also have the same problem with my code
The problem on line 40
I do i go about this error? I'm really new to matlab
% Dhtr and Dhte, for HOG of the input samples
u = ones(1,1600);
ytr = [u 2*u 3*u 4*u 5*u 6*u 7*u 8*u 9*u 10*u];
H = [];
for i = 1:1600
xi = X1600(:,i);
mi = reshape(xi,28,28);
hi = hog20(mi,7,9);
H = [H hi];
end
Dhtr = [H; ytr];
Hte = [];
for i = 1:length(Lte28)
xi = Te28(:,i);
mi = reshape(xi,28,28);
hi = hog20(mi,7,9);
Hte = [Hte hi];
end
Dhte = [Hte; 1+Lte28(:)'];
% MATLAB code for constructing Dtr and Dte for the original training and test
data sets
u = ones(1,1600);
ytr = [u 2*u 3*u 4*u 5*u 6*u 7*u 8*u 9*u 10*u];
Dtr = [X1600; ytr];
Dte = [Te28; 1+Lte28(:)'];
[ori_ws,ori_f]= SRMCC_bfgsoriML(Dtr,'f_SRMCC','g_SRMCC',0.002,10,62);
Dte(785,:) = ones(1,10000);
[~,ori_ind_pre] = max((Dte'*ori_ws)');
K = 10;
ytest = 1+Lte28(:)';
ori_C = zeros(K,K);
for j = 1:K
ind_j = find(ytest==j);
for i = 1:K
ind-pre_i = find(ori_ind_pre == i);
ori_C(i,j) = length(intersect(ind_j,ind_pre_i));
end
end
[hog_ws,hog_f]= SRMCC_bfgsML(Dtr,'f_SRMCC','g_SRMCC',0.001,10,57);
Dte(785,:) = ones(1,10000);
[~,hog_ind_pre] = max((Dte'*hog_ws)');
K = 10;
ytest = 1+Lte28(:)';
hog_C = zeros(K,K);
for j = 1:K
ind_j = find(ytest==j);
for i = 1:K
ind-pre_i = find(hog_ind_pre == i);
hog_C(i,j) = length(intersect(ind_j,ind_pre_i));
end
end
댓글 수: 6
Walter Roberson
2022년 12월 8일
That code is written for a newer version of MATLAB than you are using. Convert each place that has NAME=VALUE to 'NAME', VALUE
For example Seed=100 would be 'Seed', 100
참고 항목
카테고리
Help Center 및 File Exchange에서 Phased Array Design and Analysis에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!