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)

조회 수: 2 (최근 30일)
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
Rik
Rik 2021년 9월 4일
Is this the exact contents of the function signature? Because that is not a valid syntax.
R@SH
R@SH 2021년 9월 4일

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.

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2021년 9월 4일
You can only have variable names in your function signature, not any indexing.
function PS=level2(NOH,NOC,tetta,A)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by