Passing the input argument to the class

28 ビュー (過去 30 日間)
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2016 年 7 月 27 日
コメント済み: Steven Lord 2019 年 10 月 25 日
I need to know how can i pass the input argruments received from other function to the class
for example i got a function
function[a,b,c] = getdata(datalength, stringlength)
so now i need to pass the input arguments to the class created. How can i do it??


Adam 2016 年 7 月 27 日
If your class constructor takes arguments then just
[a, b, c] = getdata( datalength, stringlength );
myObj = myClass( a, b, c );
or if you already have an object then you need some function that accepts the 3 arguments. It is hard to say if you post nothing about your class and when/how/where it is constructed.

その他の回答 (1 件)

Ahmad Azn
Ahmad Azn 2019 年 10 月 25 日
hi guys
please help me!
how can i run this m-file?
%function [F,U,R]=ST(D)
% Analyize a Truss using the direct stiffness method
% Input D defines the Truss structure as follows
% D.Coord -- N x 3 array of node coordinates
% D.Con -- N x 2 array of connector or member mapping
% D.Re -- N x 3 array of node freedom 1 = fixed 0 = free
% D.Load -- N x 3 array of load force vectors
% D.A -- M x 1 array of member cross section areas
% D.E -- M x 1 array of member Elasticity ( Youngs Modulous)
% Ouput F -- M x 1 array of force along members
% U -- N x 3 array of Node displacement vectors
% R -- N x 3 array of Reaction force vectors
%% History
% Original code by Hossein Rahami
% 17 Mar 2007 (Updated 13 Apr 2007)
% Reformatted and comments added by
% Frank McHugh 06 Sep 2012
function [F,U,R]=ST(D)
w=size(D.Re); % 3 x number of nodes
S=zeros(3*w(2)); % stiffness matrix is 3*(number of nodes) square matrix
U=1-D.Re; % U is displacement matrix [
% column index by node
% x , y , z by rows
% initialize U to 1 for non fixed nodes 0 for fixed
f=find(U); % f index in U of free nodes
for i=1:size(D.Con,2) % Loop through Connectors (members)
C=D.Coord(:,H(2))-D.Coord(:,H(1)); % C is vector for connector i
Le=norm(C); % Le length of connector i
T=C/Le; % T is unit vector for connector i
s=T*T'; % Member Siffness matrix is of form
% k * | s -s |
% | -s s | in global truss coordinates
G=D.E(i)*D.A(i)/Le; % G aka k stiffness constant of member = E*A/L
Tj(:,i)=G*T; % Stiffness vector of this member
% indexes into Global Stiffness matrix S for this member
S(e,e)=S(e,e)+G*[s -s;-s s];
% add this members stiffness to stiffness matrix
U(f)=S(f,f)\D.Load(f); % solve for displacements of free nodes
% ie solve F = S * U for U where S is stiffness
% matrix.
%project displacement of each node pair on to member
% between
% f = Tj dot ( U2j - U1j ). Then sum over all contributing
% node pairs.
R=reshape(S*U(:),w); % compute forces at all nodes = S*U
R(f)=0; % zero free nodes leaving only reaction.
  1 件のコメント
Steven Lord
Steven Lord 2019 年 10 月 25 日
This isn't related to the topic of the original question except very loosely (they're both about calling functions.) Please ask this as a new question.


Community Treasure Hunt

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

Start Hunting!

Translated by