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

조회 수: 2 (최근 30일)
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
Temi O
Temi O 2019년 2월 8일
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 2019년 2월 8일
Did my answer below not give you an idea of how to increment the errorsCount?

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

채택된 답변

Kevin Phung
Kevin Phung 2019년 2월 7일
%%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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by