How do i select a variable for global use from an array?

1 次查看(过去 30 天)
Hi all, i was wondering how i would take a value which is inside an array and assign a variable to it, for example
i have
D=struct('Coord',Coord','Con',Con','Re',Re','Load',Load','E',E','A',A');
in which all of the inputs are relatively large vectors I want to creat a global variable call A (area) by going into this array and selecting the A from it
I have tried A = D[A] but that does not work in MATLAB
Any ideas? thanks

回答(2 个)

James Tursa
James Tursa 2011-2-26
A = D.A;
But why not just use D.A?
  3 个评论
Jiro Doke
Jiro Doke 2011-2-26
I strongly suggest going through the "Getting Started" guide in the documentation. It will save you in the long run.
Jan
Jan 2011-2-27
@David: You can mark this answer as matching your question exctly by choosing it as "accepted".

请先登录,再进行评论。


David Fraser
David Fraser 2011-2-26
To put it in better context this is the script in which D (data) is found
function D=D2
%This script uses data of Case 3
% Definition of Data
% Nodal Coordinates Coord = [0 0 0; 0 1.2 0; 3 1 0; 3 2.2 0; 5 1 0; 5 2.2 0; 8 0 0; 8 1.2 0; 1.5 0.5 0; 4.5 1 0; 6.5 0.5 0];
% Connectivity Con = [1 2; 1 9; 1 3; 2 4; 3 4; 3 10; 3 5; 4 6; 5 6; 5 11; 5 7; 6 8; 7 8; 2 9; 9 4; 4 10; 10 6; 6 11; 11 8];
% Definition of Degree of freedom (free=0 & fixed=1); for 2-D trusses the last column is equal to 1 Re=[1 1 1;0 0 1;0 0 1; 0 0 1; 0 0 1; 0 0 1; 0 1 1; 0 0 1; 0 0 1; 0 0 1; 0 0 1];
% Definition of Nodal loads Load=[0 0 0;0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0];
% Definition of Modulus of Elasticity E=[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]*(2*10e11);
% Definition of Area A=[0.007854 0.007854 0.007854 0.007854 0.007854 0.007854 0.007854 0.007854 0.007854 0.007854 0.007854 0.007854 0.007854 0.007854 0.007854 0.007854 0.007854 0.007854 0.007854];
% Convert to structure array D=struct('Coord',Coord','Con',Con','Re',Re','Load',Load','E',E','A',A');

类别

Help CenterFile Exchange 中查找有关 Variables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by