How to compare in a function definition?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
Christiaan
el 5 de Ag. de 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
Ver también
Categorías
Más información sobre MATLAB Coder en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!