!--error 21
Invalid index.
do_eval: Error while calling block Kalman_Filter_IF [uid='65b73f57:18ea0a60c83:-7fdd']: invalid parameter (ier=21.000000, %scicos_prob=
%F).
I know the error is in the below line of code are as
**[ok, x0_set, covariance_matrix, exprs] = scicos_getvalue("Set Properties and State", labels, types, exprs);**
function [x, y, typ] = Kalman_Filter_IF(job, arg1, arg2)
x = [];
y = [];
typ = [];
// Kalman filter initial state and covariance
initial_state = [0.0; 0.0]; // 2*1 matrix
initial_covariance = [1.0, 0.0; 0.0, 1.0]; // 2*2 matrix
model.cpar = initial_covariance; // Use covariance matrix as a parameter
dis
select job
// Initialize with mask parameters if any
case "set" then
x = arg1;
graphics = arg1.graphics;
exprs = graphics.exprs;
model = arg1.model;
// Create a dialog for getting user inputs
while %t do
// Initialize dialog for parameters and initial state
labels = ['Initial state [x_dot, x]', 'Covariance']; // Changed 'Stiffness' to 'Covariance'
types = list('vec', 2, 'mat', 2); // Changed 'vec' to 'mat' for Covariance
[ok, x0_set, covariance_matrix, exprs] = scicos_getvalue("Set Properties and State", labels, types, exprs);
// Check return
if ~ok then
break;
end
mess = [];
// Check parameters
// You can add additional checks for input parameters here if needed
// Accept inputs and save them
if ok then
// Concatenate the covariance matrix to the state vector
model.state = [x0_set; reshape(covariance_matrix,1,4)]; // Use the concatenation operator ":" for the matrix
graphics.exprs = exprs;
x.graphics = graphics;
x.model = model;
break;
else
message("Failed to update block io");
end
end
// Define block properties
case "define" then
// Create object
model = scicos_model();
// Provide name and type
model.sim = list("Kalman_Filter_sim", 5);
// Define inputs and outputs
// One input with a variable-size "double" element
model.in = 1; // it's only z
model.in2 = 1; // the second dimension of I/P
model.intyp = 1;
// One output with a single "double" element
model.out = [2; 2];
model.out2 = [1; 2];
model.outtyp = 1;
// Set initial state
model.state = [initial_state; matrix(initial_covariance, 4, 1)]; // Use the matrix concatenation function
// For example: [initial_state; initial_covariance(:)]
// Set default parameter
model.rpar = initial_covariance; // Use the covariance matrix as a parameter
// Define block properties
model.blocktype = "c";
model.dep_ut = [%t %f];
// Set block properties
exprs = ["[0.0; 0.0]"; "[1.0]"];
x = standard_define([4 4], model, exprs);
x.graphics.style = ["blockWithLabel;displayedLabel=Kalman_Filter"];
end
endfunction
As you can see that until 27 it is printed but after that 28 is not printed so there is issue in this line. Help me to debug it.