Error : Indices must either be real positive integers or logicals.
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
zainab malik
le 21 Oct 2018
Modifié(e) : Walter Roberson
le 25 Oct 2018
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 commentaires
Kevin Chng
le 21 Oct 2018
Modifié(e) : Kevin Chng
le 21 Oct 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.
Réponse acceptée
Kevin Chng
le 21 Oct 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
0 commentaires
Plus de réponses (1)
Image Analyst
le 21 Oct 2018
I think it's pretty well explained by the FAQ: https://matlab.wikia.com/wiki/FAQ#How_do_I_fix_the_error_.22Subscript_indices_must_either_be_real_positive_integers_or_logicals..22.3F
0 commentaires
Voir également
Catégories
En savoir plus sur Graphics Performance dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!