MATLAB Answers

how to define and write the first line of a function while one of the inputs are a matrix with strings as entries (strings are defined in the body of function)

3 views (last 30 days)
reza Shahzadi
reza Shahzadi on 4 Sep 2021
Commented: reza Shahzadi on 8 Sep 2021
I have written a code with 4 inputs which three of them are numeral and the last input is a matrix with string {'c'} or {'h'} as the possible entries for matrix.
the inputs are NOH, NOC, tetta and A[1,NOH+NOC]. [A] is a matrix in order of 1*(NOH+NOC) which the possible entries for that would be {'h'} or {'c'}. Like below examples:
NOH=2, NOC=1, tetta=pi/3, A=[{'h'} {'h'} {'c'}] or A=[{'c'} {'h'} {'h'}]
NOH=3, NOC=2, tetta=pi/4, A=[{'h'} {'c'} {'h'} {'c'} {'h'}] or A=[{'c'} {'c'} {'h'} {'h'} {'h'}]
Anyway I wrote that code and I recieved acceptable result. the summary of this code is as bellow:
NOH=input ('Please enter number of hoop layers:');
NOC=input('Please enter number of cross layers:');
tetta=input ('Please enter orientation of cross layers:');
A={}
for i=1:NOH+NOC
A(1,i)=input ('Please enter orientation of the ith layer:');
if strcmp(A(1,i),'h')
t_h(i)=(Ns*T/B)/(V_f*ro_f)
t_c(i)=0;
E_H(i)=E_x;
elseif strcmp(A(1,i),'c')
t_c(i)=((2*Ns*T)/(B*sin(tetta)))/(V_f*ro_f)
t_h(i)=0;
m=sin(tetta);
n=cos(tetta);
E_H(i)=1/((m^4/E_x)+(n^4/E_y)+(m^2*n^2/E_s)-(2*Nu_x*m^2*n^2)/E_x)
end
My problem is that, I want to turn this code into a function (PS) which will be introduced following the above code. It is reminded that, I wrote the code it has run without problem. my problem is only turning this into a function while one of the inputs of this function is a matrix with entries which are integer. I form the definition of function as bellow with the relavant body, but its not working. I would be thankful if you can possibly help me in this regard.
function[PS]=level2(NOH,NOC,tetta,[A(1,NOH+NOC)])
reavant body which has previousely worked without error and problem
...
end
  2 Comments
reza Shahzadi
reza Shahzadi on 4 Sep 2021

Hi Dear Rik, It is exactly a part of my code. I defined [A] in a "for" loop. The 1st script which I defined NOH,NOC, tetta and [A], I received result without problem. But when I want to write it in the form of function, its not possible.

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!

Translated by