Trouble with an array
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
I have some trouble with an array. I try to set the values for a 3D array (nx x ny x nz) that all inner nodes are set to a defined value, all surface nodes (except the edge nodes) are set to a defined value too. It’s like a small cube in a greater cube.
Here is the code I used:
clc;
clear all;
clf;
format short g
fontSize = 18;
% Domaine
L=0.1;
B=0.1;
H=0.1;
nx=5;
ny=5;
nz=5;
dx=L/(nx-1);
dy=B/(ny-1);
dz=H/(nz-1);
% Nodes
Tn=zeros(nx,ny,nz);
x=linspace(0,L,nx);
y=linspace(0,H,ny);
z=linspace(0,B,nz);
[X,Y,Z]=meshgrid(x,y,z);
K=zeros(nx,ny,nz);
K([1 end],:,:)=alpha;
K(:,[1 end],:)=alpha;
K(:,:,[1 end])=alpha;
% inner nodes
T=zeros(nx,ny,nz);
T(:,:,:)=700;
t=0;
% surrounding surfaces
Tu=600; % bottom
To=900; % top
Tl=400; % left
Tr=800; % rigth
Tv=300; % front
Th=300; % back
% side surfaces
Tn(1,2:nx-2,2:nz-2)=Tv; % front
Tn(ny,2:nx-2,2:nz-2)=Th; % back
Tn(2:ny-2,2:nx-2,1)=Tu; % bottom
Tn(2:ny-2,2:nx-2,nz)=To; % top
Tn(2:ny-2,1,2:nz-2)=Tl; % left
Tn(2:ny-2,nx,2:nz-2)=Tr; % rigth
% merge inner nodes
Tn(2:ny-2,2:nx-2,2:nz-2) = T(2:ny-2,2:nx-2,2:nz-2);
f = figure(1);
f.Position(3:4) = [1080 840];
%XY
subplot(2,2,1)
slice(X,Y,Z,Tn,[],[],[0,H],'cubic');
set(gca,'FontSize',fontSize)
colormap(jet)
xlabel('X -Axis','FontSize', fontSize)
ylabel('Y -Axis','FontSize', fontSize)
zlabel('Z -Axis','FontSize', fontSize)
axis([0 L 0 B 0 H]);
view(30,30);
% XZ
subplot(2,2,2)
slice(X,Y,Z,Tn,[],[0,B],[],'cubic');
set(gca,'FontSize',fontSize)
colormap(jet)
%set ( gca, 'ydir', 'reverse' )
xlabel('X -Axis','FontSize', fontSize)
ylabel('Y -Axis','FontSize', fontSize)
zlabel('Z -Axis','FontSize', fontSize)
axis([0 L 0 B 0 H]);
view(30,30);
% YZ
subplot(2,2,3)
slice(X,Y,Z,Tn,[0,L],[],[],'cubic');
set(gca,'FontSize',fontSize)
colormap(jet)
%set ( gca, 'ydir', 'reverse' )
xlabel('X -Axis','FontSize', fontSize)
ylabel('Y -Axis','FontSize', fontSize)
zlabel('Z -Axis','FontSize', fontSize)
axis([0 L 0 B 0 H]);
view(30,30);
% 3D
subplot(2,2,4)
slice(X,Y,Z,Tn,[0,L/2],[B/2,B],[0],'linear');
set(gca,'FontSize',fontSize)
set(gca,'YDir','normal')
colormap(jet)
set ( gca, 'xdir', 'reverse' )
set ( gca, 'ydir', 'reverse' )
xlabel('X -Axis','FontSize', fontSize)
ylabel('Y -Axis','FontSize', fontSize)
zlabel('Z -Axis','FontSize', fontSize)
axis([0 L 0 B 0 H])
view(-150,30);
hold on
%shading(gca,'interp')
p = get(subplot(2,2,4),'Position');
cb=colorbar('Position', [0.93 0.25 0.025 0.6]);
set(cb,'FontSize',fontSize);
caxis([0, 900]);
The result I achieve is this:
I marked the false areas with a red sign. I indexed from 2:nx-1 and so on, but it's not working.
The result should look like this:
I don't know where the error is. Maybe someone has a clue how to fix this.
Greetings
Steffen
0 件のコメント
採用された回答
UDAYA PEDDIRAJU
2024 年 8 月 23 日
Hey Steffen,
As per my understanding the following issue is found and modify in the code accordingly:
Indexing: The indexing for the surface nodes are suggested to use "2:nx-1, 2:ny-1," and "2:nz-1' instead of "2:nx-2, 2:ny-2," and "2:nz-2". This ensures that the edge nodes are excluded from the surface assignments.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で MATLAB Support Package for USB Webcams についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!