Incorrect use of '=' operator. To assign a value to a variable, use '='. To compare values for equality, use '=='.

255 views (last 30 days)
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

Accepted Answer

Stephen23
Stephen23 on 24 May 2019
Edited: Stephen23 on 24 May 2019
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.

More Answers (2)

Tareq Rahmani
Tareq Rahmani on 23 Mar 2020
what is wrong here :

Simbarashe Zuva
Simbarashe Zuva on 24 Dec 2021
Edited: Walter Roberson on 24 Dec 2021
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);
Incorrect use of '=' operator. Assign a value to a variable using '=' and compare values for equality using '=='.
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 Comments
Walter Roberson
Walter Roberson on 8 Dec 2022
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

Sign in to comment.

Categories

Find more on Phased Array Design and Analysis in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!