Effacer les filtres
Effacer les filtres

How do I write an if statement that says a variable is a error given a condition?

2 vues (au cours des 30 derniers jours)
Please how do I write this 'if statement' in MATLAB notation? I ran a simulation N times and would like to find the error rate using an 'if statement'. I ran the simulation N number of times. How do I write that Y is an error if the statement below happens? And then calculate the errors in N number of trials?
if X=1.2||Y=0 && U1>U2
%How do I write that Y is an error if the above statement happens? And then calculate the number of errors in N number of trials?
end
  10 commentaires
Temi O
Temi O le 8 Fév 2019
Actually, I think you're right. I'm a beginner on MATLAB and still trying to understand how it works. I think the correct if statement is below. How do I count the error rate:
function [x1,x2,errorRate,rTime]= RightsimulateDDM(U1,U2,dT,a,To)
N= 1000; %number of simulations performed
rTime= zeros(1,N);%create a row vector for the reaction time of each simulation
for trialNumber= 1:N
x1(1)= 0.5*a;
x2(1)= 0.5*a;
i=1;
while x1(i) < a && x2(i)<a
noise1= sqrt(dT)*randn;
noise2= sqrt(dT)*randn;
x1(i+1)= x(i)+ dT*(U1 -U2)+ noise1-noise2;
x2(i+1)= x2(i)+ dT*(U2 -U1)+ noise2-noise1;
i=i+1;
end
rTime(trialNumber)= To + (i-1)*dT;
if U1> U2 %When this is the case, x2>a is an error
if x2(i)>= a
error=1
else error=0
end
end
if U2> U1 %When this is the case, x1>a is an error
if x1(i)>= a
error=1
else error=0
end
end
errorCount= %Not sure of how to do this
errorRate= errorCount/N
clear x1 x2
end
Kevin Phung
Kevin Phung le 8 Fév 2019
Did my answer below not give you an idea of how to increment the errorsCount?

Connectez-vous pour commenter.

Réponse acceptée

Kevin Phung
Kevin Phung le 7 Fév 2019
%%outside forloop
errCnt = 0;
%% inside forloop
if X=1.2||Y=0 && U1>U2
%How do I write that Y is an error if the above statement happens?
disp(['Error found in iteration ' num2str(i)])
% And then calculate the number of errors in N number of trials?
errCnt = errCnt + 1;
end
%%
something like that. If you're looping through Y, dont forget to change it to Y(i)

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by