Anonymous functions usage when running the following program to apply and then plot a prediction, sensor reading and measurement update Invalid expression.

I get error on the foll. program
"Invalid expression. When calling a function or indexing a variable, use parentheses.
Otherwise, check for mismatched delimiters."
U = [ 1 -1 3 4 ]; % an artificial input sequence
% applyPredictionUpdate returns the predicted state:
applyPredictionUpdate = @(bel, u_t) [bel '.PU(' num2str(u_t) ')'];
% readSensor returns the current sensor's reading:
readSensor = @() [ 'Z(' num2str(round(20*rand())) ')' ];
% applyMeasurementUpdate returns the state updated by the measurements:
applyMeasurementUpdate = @(sensorReading, belBar) [ belBar '.MU(' sensorReading ')' ];
bel = 'PRIOR';
for u_t = U
applyPredictionUpdate(bel, u_t);
readSensor();
applyMeasurementUpdate((sensorReading, belBar)[sensorReading, belBar]);
end
plotFilterLoop(bel);

1 comentario

Tried this got:"Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters."

Iniciar sesión para comentar.

 Respuesta aceptada

Thanks, tried but error:
"Unrecognized function or variable 'sensorReading'.
Error in solution (line 14)
applyMeasurementUpdate(sensorReading, belBar);"

6 comentarios

If sensorReading is the variable you want to use as the first input to the function applyMeasurementUpdate, then you will have to define sensorReading before you use it to call applyMeasurementUpdate.
Maybe it should be:
applyMeasurementUpdate(readSensor(), bel);
(wild guess)
Tried, got
"Sorry, but bel=PRIOR is the wrong final belief state. Check the order of the update steps."
That's good news, because now you're getting beyond MATLAB syntax errors and into errors from within the code that your code is trying to run.
Probably check the documentation for that code to find out what "bel=PRIOR is the wrong final belief state. Check the order of the update steps." means and how to fix it.
Checked the doc. - problem is that the bel in applyPredictionUpdate(bel, u_t); does not store the changed value, so after the applyP---, bel has to be stored in another variable say "a" and then used. I tried to store in "a" as shown - no luck. Any ideas appreciated.
for u_t = U
applyPredictionUpdate(bel, u_t);
a=applyPredictionUpdate(bel, u_t);
readSensor();
applyMeasurementUpdate(readSensor(),a);
end
Voss
Voss el 29 de Mzo. de 2022
Editada: Voss el 29 de Mzo. de 2022
I'm not familiar with the MATLAB toolbox or 3rd party package that this is using, so I'm afraid I wouldn't be able to help.
Maybe start a new question about the error(s) you see and specify which MATLAB toolbox or 3rd party package you are using.

Iniciar sesión para comentar.

Más respuestas (1)

applyMeasurementUpdate is an anonymous function defined to take two inputs, sensorReading and belBar:
applyMeasurementUpdate = @(sensorReading, belBar) [ belBar '.MU(' sensorReading ')' ];
When calling applyMeasurementUpdate, you only need to give it those two inputs, like this:
applyMeasurementUpdate(sensorReading, belBar);
Just like you are calling applyPredictionUpdate with inputs bel and u_t a couple of lines above:
applyPredictionUpdate(bel, u_t);

Categorías

Etiquetas

Preguntada:

Ken
el 26 de Mzo. de 2022

Editada:

el 29 de Mzo. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by