Mystery Error; same code runs fine the in 2023a version Matlab, but not the 2023b!

2 views (last 30 days)
So, many errors occur in below attached code i want to create finite element mesh of medical images but now i am unable to use this code properly on every steps i get some error i dont what wrong with this code. please suggest me it will be higly appreciable.
clc
close all
clear
filename = fullfile("C:\Users\DELL\OneDrive\Documents\MATLAB\MedicalLabelingSession6\LabelData\8_19_2021_11_41_40_AM.nii");
labelVol = medicalVolume(filename);
R = labelVol.VolumeGeometry;
isovalue = 0.12;
[faces,vertices] = extractIsosurface(labelVol.Voxels,isovalue);
I = vertices(:,1);
J = vertices(:,2);
K = vertices(:,3);
[X,Y,Z] = intrinsicToWorld(R,I,J,K);
verticesPatient = [X Y Z];
verticesPatientMeters = verticesPatient.*10^-3;
triangul = triangulation(double(faces),double(verticesPatientMeters));
viewer = viewer3d;
s = images.ui.graphics3d.Surface(viewer,data=triangul,Color=[1 0 0],Alpha=0.9);
%%
model = createpde(3);
geometryFromMesh(model,verticesPatientMeters',faces');
pdegplot(model,FaceLabels="on")
%%
hMax = 0.0016;
msh = generateMesh(model,Hmax=hMax,Hmin=hMax/2);
pdemesh(model);
%%
DCMData = medicalVolume(filename);
trueIdx = find(labelVol.Voxels==1);
HUVertebra = double(DCMData.Voxels(trueIdx));
[row,col,slice] = ind2sub(size(labelVol.Voxels),trueIdx);
[X2,Y2,Z2] = intrinsicToWorld(R,col,row,slice);
HUVertebraMeters = [X2 Y2 Z2].*10^-3;
F = scatteredInterpolant(HUVertebraMeters,HUVertebra);
%%
%%
ccoeffunc = @(location,state) HU2TransverseIsotropy(location,state,F);
specifyCoefficients(model,'m',0, ...
'd',0, ...
'c',ccoeffunc, ...
'a',0, ...
'f',[0;0;0]);
%%
bottomSurfaceFace = 1;
topSurfaceFace = 250;
forceInput = -3000;
nf2=findNodes(model.Mesh,"region",Face=topSurfaceFace);
positions = model.Mesh.Nodes(:,nf2)';
surfaceShape = alphaShape(positions(:,1:2));
faceArea = area(surfaceShape);
inputPressure_Pa = forceInput/faceArea;
applyBoundaryCondition(model,"dirichlet",Face=bottomSurfaceFace,u=[0,0,0]);
applyBoundaryCondition(model,"neumann",Face=topSurfaceFace,g=[0;0;inputPressure_Pa]);
Rs = solvepde(model);
%%
Uz = Rs.NodalSolution(:,3)*10^3;
pdeplot3D(model,"ColorMapData",Uz)
clim([-0.15 0])
title("Axial Displacement (mm)")
%%
x = min(msh.Nodes(1,:)):0.001:max(msh.Nodes(1,:));
y = min(msh.Nodes(2,:)):0.001:max(msh.Nodes(2,:));
z = min(msh.Nodes(3,:))+0.5*(max(msh.Nodes(3,:))-min(msh.Nodes(3,:)));
[Xg,Yg] = meshgrid(x,y);
Zg = z*ones(size(Xg));
%%
U = interpolateSolution(Rs,Xg,Yg,Zg,3);
U = U*10^3;
Ug = reshape(U,size(Xg));
%%
surf(Xg,Yg,Ug,LineStyle="none")
axis equal
grid off
view(0,90)
colormap("turbo")
colorbar
clim([-0.15 0])
title("Axial Displacement (mm)")
%%
[cgradx,cgrady,cgradz] = evaluateCGradient(Rs,Xg,Yg,Zg,3);
%%
cgradz = cgradz*10^-6;
cgradzg = reshape(cgradz,size(Xg));
%%
surf(Xg,Yg,cgradzg,LineStyle="none");
axis equal
grid off
view(0,90)
colormap("turbo")
colorbar
clim([-10 1])
title("Axial Stress (MPa)")
%%
[gradx,grady,gradz] = evaluateGradient(Rs,Xg,Yg,Zg,3);
gradzg = reshape(gradz,size(Xg));
surf(Xg,Yg,gradzg,LineStyle="none");
axis equal
grid off
view(0,90)
colormap("turbo")
colorbar
clim([-0.008 0])
title("Axial Strain")
  5 Comments
dpb
dpb on 7 Oct 2023
Did it solve the pde with earlier version you said "ran well"?
If so, and there is no significant difference between that model and the revised code, I'd suggest sending to Mathworks support the previous and current versions (including results/timing for prior case) and ask for help.
There's nothing anybody here can do simply by looking at the code; we do not have your data to try to duplicate anybody who has the necessry toolboxen -- I don't, for one.

Sign in to comment.

Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!