Error : Indices must either be real positive integers or logicals.

7 Ansichten (letzte 30 Tage)

when I change number of nodes from 4 to 8 I get this

Error: Subscript indices must either be real positive integers or logicals.
                                                                 Error in RectangularPlate22 (line 63)
                                                                  X(:,iel) = coordinates(nodes(iel,:),1) ;_|

How could i resolvethis error and make it working for 8 nodes per element???

% Variable Description:
%           L - Length of the Plate along X-axes
%           B - Breadth of the Plate along Y-axes
%           Nx - Number of Elements along X-axes
%           Ny - Number of Elements along Y-axes
%           coordinates - The nodal coordinates of the mesh
%           -----> coordinates = [node X Y] 
%           nodes - The nodal connectivity of the elements
%           -----> nodes = [node1 node2......]    
%--------------------------------------------------------------------------
clc ; clear all ;
% Variables which can be changed
% Dimensions of the plate
L = 0.5 ;             % Length of the Plate along X-axes
B = 0.5 ;             % Breadth of the Plate along Y-axes
% Number of Elements required 
Nx = 20 ;            % Number of Elements along X-axes
Ny = 20 ;            % Number of Elements along Y-axes
%----------------------------------------
% From here dont change
nel = Nx*Ny ;        % Total Number of Elements in the Mesh
nnel = 8 ;           % Number of nodes per Element
% Number of points on the Length and Breadth
npx = Nx+1 ;
npy = Ny+1 ;
nnode = npx*npy ;      % Total Number of Nodes in the Mesh
% Discretizing the Length and Breadth of the plate
nx = linspace(0,L,npx) ;
ny = linspace(0,B,npy) ;
[xx, yy] = meshgrid(nx,ny) ;
% To get the Nodal Connectivity Matrix
coordinates = [xx(:) yy(:)] ;
NodeNo = 1:nnode ;
nodes = zeros(nel,nnel) ;
% If elements along the X-axes and Y-axes are equal
if npx==npy
    NodeNo = reshape(NodeNo,npx,npy);
    nodes(:,1) = reshape(NodeNo(1:npx-1,1:npy-1),nel,1);
    nodes(:,2) = reshape(NodeNo(2:npx,1:npy-1),nel,1);
    nodes(:,3) = reshape(NodeNo(2:npx,2:npy),nel,1);
    nodes(:,4) = reshape(NodeNo(1:npx-1,2:npy),nel,1);
end
%
% Plotting the Finite Element Mesh
% Initialization of the required matrices
X = zeros(nnel,nel) ;
Y = zeros(nnel,nel) ;
% Extract X,Y coordinates for the (iel)-th element
  for iel = 1:nel
      X(:,iel) = coordinates(nodes(iel,:),1) ;
      Y(:,iel) = coordinates(nodes(iel,:),2) ;
  end 
% Figure
fh = figure ;
set(fh,'name','Preprocessing for FEA','numbertitle','off','color','w') ;
patch(X,Y,'w')
title('Finite Element Mesh of Plate') ;
axis([0. L*1.01 0. B*1.01])
axis off ;
if L==B
    axis equal ;
end
  7 Kommentare
zainab malik
zainab malik am 21 Okt. 2018
Thank you KevinChng Sir!! Could you please help me also in this that when I try to display node and element number by adding the below lines at the end of node.
if true
% code
% To display Node Numbers % Element Numbers
pos = [70 20 60 20] ;
ShowNodes = uicontrol('style','toggle','string','nodes','value',0,....
'position',[pos(1) pos(2) pos(3) pos(4)],'background','white','callback',...
@(varargin) SHOWN(ShowNodes,ShowElements,coordinates,X,Y,nnode,nel,nodes));
pos = get(ShowNodes,'position') ;
pos = [2*pos(1) pos(2) pos(3) pos(4)] ;
ShowElements = uicontrol('style','toggle','string','Elements','value',0,....
'position',[pos(1) pos(2) pos(3) pos(4)],'background','white','callback',....
@(varargin) SHOWELEMENTS(ShowElements,ShowNodes,coordinates,X,Y,nel,nodes,nnode));
I get
Error : Undefined function or variable 'SHOWNODES'. Error while evaluating UIControl Callback
How I resolve this?
Kevin Chng
Kevin Chng am 21 Okt. 2018
Bearbeitet: Kevin Chng am 21 Okt. 2018
Hi,
at my first glance, your error is
'callback',...
@(varargin) SHOWN(ShowNodes,ShowElements,coordinates,X,Y,nnode,nel,nodes)
I'm not really remember how to write the syntax to pass argument for callback. Usually, i will use handles and pass the handles to the callback function. More information, you can refer to link below:
However,
1st) ShowElemet has yet declared, you can't put him into the argument pass to your callback function
2nd) Put the object name into his own callback function, i guess it is not a proper way to do. Refer to code below on how to get your uicontrol object information.
slider = uicontrol('Parent', hfig,'Style','slider',...
'Units','normalized',...
'Position',[0.3 0.5 0.4 0.1],...
'Tag','slider1',...
'Callback',@slider_callback);
function slider_callback(hObject,eventdata)
data = guidata(hObject);
data.val = hObject.Value;
data.diffMax = hObject.Max - data.val;
% For R2014a and earlier:
% data.val = get(hObject,'Value');
% maxval = get(hObject,'Max');
% data.diffMax = maxval - data.val;
guidata(hObject,data);
end
Refer to code above, in your callback function, you simply use guidata(hObject) to get the information of your slider.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Kevin Chng
Kevin Chng am 21 Okt. 2018
I think your error is from here
nodes(iel,:)
first you assign zero to nodes with 400 x 8 dimension
nodes = zeros(nel,nnel) ;
later in your reshape you assign dimension 21*21 to NodeNo
NodeNo = reshape(NodeNo,npx,npy);
Then reshape nodes follow below
nodes(:,1) = reshape(NodeNo(1:npx-1,1:npy-1),nel,1);
that's mean now nodes(:,1) has dimesion 441 * 1 then you do similar thing to nodes(:,2), nodes(:,3), nodes(:,4).
Now, Try to think, what is the dimension of nodes(:,5)? originally, you assign zero to nodes(:,5) from 1 to 400, then with new expansion of your nodes, 401 to 441 will be NaN.
At the end
X(:,iel) = coordinates(NaN,1) ;
So how to solve it ? I guess simply to change this line to 21*21 dimension
nodes = zeros(npx,npy) ;
% your npx is 21 dimension, npy is also 21 dimension

Weitere Antworten (1)

Image Analyst
Image Analyst am 21 Okt. 2018

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by