# What is best way to debug if we dont know the invalid index in XCOS?

**URL:** <https://scilab.discourse.group/t/what-is-best-way-to-debug-if-we-dont-know-the-invalid-index-in-xcos/457>\
**Category:** Xcos\
**Created:** [April 8, 2024, 5:48pm UTC](https://scilab.discourse.group/t/what-is-best-way-to-debug-if-we-dont-know-the-invalid-index-in-xcos/457 "2024-04-08T17:48:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vimsrocz](https://avatars.discourse-cdn.com/v4/letter/v/ed8c4c/32.png) [@Vimsrocz](https://scilab.discourse.group/u/Vimsrocz)\
**Post date:** [April 8, 2024, 5:48pm UTC](https://scilab.discourse.group/t/what-is-best-way-to-debug-if-we-dont-know-the-invalid-index-in-xcos/457/1 "2024-04-08T17:48:27Z")

</div>

```auto
  !--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 👎

```auto
**[ok, x0_set, covariance_matrix, exprs] = scicos_getvalue("Set Properties and State", labels, types, exprs);**

```

```auto
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

```

 ![Capture](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/4b990df5748c26b25b8fa23495ab27ef214aae5e.jpeg)  
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.
