dot indexing is not supported for variables of this type

206 views (last 30 days)
CODE:
function F = system_of_equations(x)
global def;
global m;
global init;
global P_alpha_1;
s=def.k ;
C1=x(1,1:s);
C2=x(1,(s+1):2*s);
x1=(C1*P_alpha_1*m.H) + init(1);
u=(C2*m.H) ;
D_alpha1_x1=C1*m.H;
%
M=Haar_matrix(s);
HC=M(:,s);
%%control law1
F = horzcat( D_alpha1_x1 + x1 - u , ...
(C1*P_alpha_1*HC) + init(1) - (1/2*((1-exp(-1))^2))) ;
end
I am getting an error as
Dot indexing is not supported for variables of this type.
Error in system_of_equations (line 10)
s=def.k
I am running the function as system_of_equations(zeros(1,16)) and getting the above error.
How to solve this problem?
  2 Comments
KSSV
KSSV on 18 Feb 2022
What is
class(def)
You are trying to access it like a structure. Is it a structure?
Kunal Jain
Kunal Jain on 18 Feb 2022
Thanks for answering my question.
By using s=def.k , I have triying to define a matrix C1 and and C2 as given.
C1=x(1,1:s);
C2=x(1,(s+1):2*s);
Can you tell how is it coming as a structure and what should be the changes?
Thanks in advance

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 18 Feb 2022
The global variable def was not initialized, so it has the default value that global variables have, 0x0 double precision array. Double precision arrays cannot be dot-indexed.
Moral of the story is to avoid using global variables.

Bjorn Gustavsson
Bjorn Gustavsson on 18 Feb 2022
Try your hardest to avoid global variables. They typically lead to bugs and errors that are hard to understand and trace - because they can be caused by variable-modifications far from the function where the errors appear. In this case use additional input-variables to your function:
function F = system_of_equations(x,def, m, init, P_alpha_1)
% global def;
% global m;
% global init;
%
% global P_alpha_1;
s=def.k ;
C1=x(1,1:s);
C2=x(1,(s+1):2*s);
x1=(C1*P_alpha_1*m.H) + init(1);
u=(C2*m.H) ;
D_alpha1_x1=C1*m.H;
%
M=Haar_matrix(s);
HC=M(:,s);
%%control law1
F = horzcat( D_alpha1_x1 + x1 - u , ...
(C1*P_alpha_1*HC) + init(1) - (1/2*((1-exp(-1))^2))) ;
end
Then you will know what variables you send in to the function and can be sure of what they represent.
In your case you might have called another function that also defined a global variable def and then assigned some value to that, for example any of these:
def = pi^.5;
def = 'my favourite global variable';
def = {exp(1i*pi*(sqrt(5)+1)/2),'well'};
and then your carefully designed def will be poofed out of existens.
Try your very hardest to avoid global variables.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!