How to compare in a function definition?

2 vues (au cours des 30 derniers jours)
Doc22
Doc22 le 5 Août 2015
Commenté : Doc22 le 5 Août 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.

Réponses (1)

Christiaan
Christiaan le 5 Août 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 commentaire
Doc22
Doc22 le 5 Août 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB Coder dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by