How to turn a code into a function while one of the input is string
Show older comments
I wrote a code and it works without ant error or problem. I want to turn it in to a function. this function has 4 input which 3 of them are numeral and the last one is a matrix with strings as its entries. Here is the summary of the code I wrote:
NOH=input ('Please enter number of hoop layers:');
NOC=input('Please enter number of cross layers:');
tetta=input ('Please enter orientation of cross layers:');
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;
tetta=pi/2;
end
elseif strcmp(A(1,i),'c')
t_c(i)=(2*Ns*T/B*sin(tetta))/(V_f*ro_f);
t_h(i)=0;
end
As it can be observed NOH,NOC, tetta are 3 numeral variable and A[1,NOH+NOC] is a matrix which entries of that could be {'h'} or {'c'}.
I wrote this function as below but its not working. I really appreciate your kind instructions in this matter.
function[PS]=stiffness1(NOH,NOC,tetta,[A(1,NOH+NOC)])
.....
end
2 Comments
Geoff Hayes
on 3 Sep 2021
reza - please see declare function name, inputs, etc. that describes how to define the inputs to this function. In this case, your fourth input is not a valid input parameter. What is the intent as I don't see how it is used in your code? Or are you trying to define what A should be? i.e. an array that is 1x(N0H+N0C) and so want to pass that into the function. Will the function then determine the different elements for A using the
A(1,i)=input ('Please enter orientation of the ith layer:');
Perhaps you need to show the body of the function.
R@SH
on 4 Sep 2021
Accepted Answer
More Answers (0)
Categories
Find more on App Building in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!