Dot indexing is not supported for variables of this type.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kiran Patil
am 4 Mai 2020
Kommentiert: Kiran Patil
am 4 Mai 2020
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 Kommentare
Akzeptierte Antwort
Guillaume
am 4 Mai 2020
Bearbeitet: Guillaume
am 4 Mai 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!