Dot indexing is not supported for variables of this type.

3 visualizzazioni (ultimi 30 giorni)
please someone help me with this as soon as possible as i have a submission due.
I am new to Matlab,and i dont know why this error pops up in mycod.This code is same to all other students and they are able to run it and i am not.
1)L2_1D_P3 file (which i run )
clear;format long;
%Computational domain
Lx=1;
%Local variables
XSeed= 11;
%Diffusity function
diffusivity_function=struct('type','scalar','d',1.0);
%Volumeteric Source
load_type=struct('case','homogeneous','value',1.0);
%Standard data
dim=1;dofs_per_node=1;
EleType='L2';
NGPTS=3;
%Nele and NumNodes
Nele= XSeed-1;
NumNodes=XSeed;
%Coordinate matrix
Coord=zeros(NumNodes,dim);
for row =1:XSeed
Coord(row)=Lx*(row-1)/(XSeed-1);
end
%Connectivity matrix
Connectivity=zeros(Nele,2);
for ele = 1:Nele
Connectivity(ele,:)=[ele,ele+1];
end
%Constraints matrix
Constraints=[1,1,0];
NCons= size(Constraints,1);
%Call the driver to run simulation
[U] = Driver_Steady_Diffusion(Connectivity,Constraints,...
Coord,dim,dofs_per_node,diffusivity_function,EleType,load_type,NCons,...
Nele,NGPTS,NumNodes);
%Colorful plots
plot(Coord,U,'k*','MarkerSize',20);hold on;
plot(Coord,Coord.*(Lx-Coord/2),'b-','LineWidth',2);
Legend('Numerical','Analytical','FontSize',20);
xlabel('x','FontSize',20);
ylabel('c(x)','FontSize',20);
2) Get_Volumetric source(where the error is)
function [f]= Get_VolumetricSource(load_type,x)
if strcmpi(load_type.case,'homogeneous')
f=load_type.value;
return;
end
my error message: when i run for L2_1D_P3 file
L2_1D_P3
__________________________________________
Diffusion Simulation Status Report
__________________________________________
Step1:Create GlobalId Vector
Step2:Create constraints vector
Step3: Calculate global stiffness matrix and load vector;
Dot indexing is not supported for variables of this type.
Error in Get_VolumetricSource (line 5)
if strcmpi(load_type.case,'homogeneous')
Error in CalculateLocalMatrices (line 34)
rlocal=rlocal+w(gpt)*N'*Get_VolumetricSource(load_type,x)*detJ;
Error in CalculateGlobalMatrices (line 30)
[klocal,rlocal]=CalculateLocalMatrices(diffusivity_function,EleNodes,EleType,...
Error in Driver_Steady_Diffusion (line 36)
[K_FF,K_FP,R_F]=CalculateGlobalMatrices(Connectivity,...
Error in L2_1D_P3 (line 39)
[U] = Driver_Steady_Diffusion(Connectivity,Constraints,...
  8 Commenti
Kiran Patil
Kiran Patil il 4 Mag 2020
sorry , but i am very new to any type of coding laguage.can you send me any links or source like youtube where i can know how to debug line by line as you said,
Kiran Patil
Kiran Patil il 4 Mag 2020
1) this is a function
function [f]= Get_VolumetricSource(load_type,x)
if strcmpi(load_type.case,'homogeneous')
f=load_type.value;
print load_type.case
return;
end
2) this is input ( where i tell what is load_type ( case and its value)
load_type= struct('case','homogeneous','value',0.0);
3)this is where i want it to give me the f output
f= Get_VolumetricSource(load_type,x);
4)i am using this f for further multiplication with other variables .
rlocal=rlocal+w(gpt)*N'*f*detJ;

Accedi per commentare.

Risposta accettata

Guillaume
Guillaume il 4 Mag 2020
Modificato: Guillaume il 4 Mag 2020
What the error message is telling you is that in Get_VolumetricSource at the point you do:
if strcmpi(load_type.case,'homogeneous')
load_type is not a structure (or something else that supports dot indexing).
Indeed, you created load_type as a structure in your script, so there's a problem in between where it gets replaced by something else and you need to find where. The error message also gives you the call stack, it's going through Driver_Steady_Diffusion, then CalculateGlobalMatrices, then CalculateLocalMatrices, and finally . Note that it may have a different name in each function.
As Rik said, you need to debug your code. Follow the process detailed in the documentation, put a breakpoint at the start of your script and step through the code line by line, observing the state of each variable as they change, in particular that load_type variable and see where its content get replaced by something else. You could also first set a breakpoint at the start of Get_VolumetricSource and see what is actually in load_type when it gets called.
edit:
In Driver_Steady_Diffusion, you have:
[K_FF,K_FP,R_F]=CalculateGlobalMatrices(Connectivity,...
Coord,diffusivity_function,dim,dofs_per_node,EleType,load_type,GlobalID,...
NCons,Nele,NEqns,NGPTS);
load_type is the 7th argument passed to CalculateGlobalMatrices
The signature of CalculateGlobalMatrices is:
function [K_FF,K_FP,R_F]=CalculateGlobalMatrices(Connectivity,...
Coord,diffusivity_function,dim,dofs_per_node,EleType,GlobalID,load_type,...
NCons,Nele,NEqns,NGPTS)
where load_type is the 8th argument. So there's your problem, load_type and GlobalID get swapped. Note that in matlab (and the majority of other programming languages), the name of the arguments is not important, it's their position that is critical.
  1 Commento
Kiran Patil
Kiran Patil il 4 Mag 2020
thank you , very much , it now doesnt show the error and i understood who this coding thing works

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by