Search code examples
matlabdimensionsdimensionscilabincompatibletypeerror

Incompatible dimensions [scilab] or [Matlab]


i want to test this program with scilab, but when i run it, i get this error :

ATTENTION: Transposition of the line X vector to obtain compatible dimensions plot2d: Wrong dimension of input arguments: Incompatible dimensions.

here is the program :

t=0:400;
if t>=0 & t<=20 then
   v=0
else 
   v=15
end
plot(t,v)

Solution

  • I think you are attempting to create a vector v whose values depend on the values of t. This means that where t is between 0 and 20, then v must be equal to 0, otherwise it must be equal to 15.

    This code should produce what you are looking for:

    t = 0:400;
    
    v = zeros(size(t));
    v(t > 20) = 15;
    
    plot(t,v);
    

    Actually, you have to create a zero-filled vector v of the same size of t and then, using a logical indexing, you have to set the values of v to 15 in correspondance of t being greater than 20.