How to compare in a function definition?

2 views (last 30 days)
Doc22
Doc22 on 5 Aug 2015
Commented: Doc22 on 5 Aug 2015
Hi. I have to write a code for the following function:
calMeasurement = @(Z, M, pTrueDetection, pFalseDetection)[....
Here if z is equal to M, then pTrueDetection should be the output and if it is not them pFalseDetection should be the output. Z and M are 3X3 matrices and have either 1 or 0 as their elements. also these should multiply as the loop moves forward. Here is the main loop.
for i = 1:worldRows
for j = 1:worldCols
x = [i, j];
lPerception(i, j) = ...
calcPMeasurement(Z, getVisibleSubMap(x, Mglobal), ...
pTrueDetection, pFalseDetection);
end
end
So if first output is true and next is false them combined output should be pTrueDetection X pFalseDetection. I'm new to Matlab and I can't figure this out. Please help.

Answers (1)

Christiaan
Christiaan on 5 Aug 2015
Dear Mr or Sir,
Here is an example how you could compare the matrix and use either a true or false variable for replacement. I hope this is what you had in mind/helps you further.
clc;clear;
Z = round(rand(3,3))
M = round(rand(3,3))
pTrueDetection = 5;
pFalseDetection = 8;
for i=1:3
for j=1:3
if Z(i,j)==M(i,j)
Z(i,j) = pTrueDetection;
M(i,j) = pTrueDetection;
else
Z(i,j) = pFalseDetection;
M(i,j) = pFalseDetection;
end
end
end
Z
Kind regards, Christiaan
  1 Comment
Doc22
Doc22 on 5 Aug 2015
Hi Christiaan. Thanks for your prompt reply. However, this will not help me because it is mandatory for me to change only the function. I cannot alter the loop or the rest of the program in any way. I am provided with values as the simulator moves across the plane. I cannot change the values of Z, M, pTrueDetection and pFalseDetection. I have to use them to calculate the total probability.
Thank you for your help.
PS: It is Ms.

Sign in to comment.

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!