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)

4 views (last 30 days)
R@SH on 4 Sep 2021
Commented: R@SH 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:');
for i=1:NOH+NOC
A(1,i)=input ('Please enter orientation of the ith layer:');
if strcmp(A(1,i),'h')
elseif strcmp(A(1,i),'c')
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.
reavant body which has previousely worked without error and problem
R@SH 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)



Community Treasure Hunt

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

Start Hunting!

Translated by