dot indexing is not supported for variables of this type

99 vues (au cours des 30 derniers jours)
Kunal Jain
Kunal Jain le 18 Fév 2022
Réponse apportée : zaam le 3 Mai 2025
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 commentaires
KSSV
KSSV le 18 Fév 2022
What is
class(def)
You are trying to access it like a structure. Is it a structure?
Kunal Jain
Kunal Jain le 18 Fév 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

Connectez-vous pour commenter.

Réponses (3)

Walter Roberson
Walter Roberson le 18 Fév 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 le 18 Fév 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.

zaam
zaam le 3 Mai 2025
Error evaluating the initialization for MATLAB S-Function 'animrule'. The following is the MATLAB call stack (file names and line numbers) that produced this error:
['C:\Program Files\MATLAB\R2023a\toolbox\fuzzy\fuzzy\animrule.m'] [42]
['C:\Program Files\MATLAB\R2023a\toolbox\fuzzy\fuzzy\animrule.m'] [34]
['C:\Program Files\MATLAB\R2023a\toolbox\fuzzy\fuzzy\animrule.m'] [13]
['C:\Program Files\MATLAB\R2023a\toolbox\shared\spcuilib\slscopes\+Simulink\+scopes\+source\@WiredSource\sendSimulationCommand.m'] [16]
['C:\Program Files\MATLAB\R2023a\toolbox\shared\spcuilib\unifiedscopes\+uiservices\fevalNoBacktrace.m'] [10]
['C:\Program Files\MATLAB\R2023a\toolbox\shared\spcuilib\slscopes\+Simulink\+scopes\+source\@WiredSource\sendSimulationCommand.m'] [16]
['C:\Program Files\MATLAB\R2023a\toolbox\shared\spcuilib\slscopes\+Simulink\+scopes\+source\@PlaybackControls\slPlayPause.p'] [0]
['C:\Program Files\MATLAB\R2023a\toolbox\shared\spcuilib\slscopes\+Simulink\+scopes\+source\@PlaybackControls\PlaybackControls.p'] [0]
Caused by:
Dot indexing is not supported for variables of this type.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by