How to compare in a function definition?

2 次查看(过去 30 天)
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.

回答(1 个)

Christiaan
Christiaan 2015-8-5
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 个评论
Doc22
Doc22 2015-8-5
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by