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
2021-9-4
Is this the exact contents of the function signature? Because that is not a valid syntax.
采纳的回答
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 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!