Can you give a few examples of some functions(been a while since I did this....ie: a few years since college)?? It looks like it isn't an issue of your programming syntax. To the poster above, Matlab doesn't really care about semi colons for anything other than surpressing output, so that isn't his issue at all. Sure it may come down to clean code, but that is irrelevant here.
The problem probably isn't that you aren't writing matlab correctly, but you probably aren't thinking about what you want to acheive, and you aren't thinking about the actual inputs and outputs from each function.
function [c] =RHP_from_unity_fb(G)
% checks to make sure if system G has any poles in the RHP
c= pole(G);
if c>0
disp('1')
elseif c==0;
disp('0')
else
disp('-1')
end
I bet you 100 dollars that the bolded line is where you have your problem. Actually, its the FIRST problem you have. What is the output of the 'POLE' function? Pulling up matlab right now, this is what I'm seeing:
Code:
POLE Compute the poles of LTI models.
P = POLE(SYS) computes the poles P of the LTI model SYS (P is
a column vector).
For state-space models, the poles are the eigenvalues of the A
matrix or the generalized eigenvalues of the (A,E) pair in the
descriptor case.
P = POLE(SYS,J1,...,JN) computes the poles P of the model with
subscripts (J1,...,JN) in the model array SYS.
So it looks like the output of P is a column vector (multiple rows, one column). I’m not positive EXACTLY how the output should be interpreted, but I can take you thiss
What you probably need to do is as follows: test each element (use the FIND function) to see if any of the elements exist in either plane.
Your cases are as follows:
Are any poles in the right hand plane?
Are any poles in the left hand plane?
Are poles only the left hand plane (but have an imaginary component)?
For the first you can go (FIND c > 0 ) % assumes that if element of vector C (nx1 vector) is > 0, it is on the right side
For the second you can go (FIND c 0) %assumes that if element of vector C (nx1 vector)< 0, it is on the left right
For the last you can proceed similarly.
Here is a quick code check for the first
Code:
cat = FIND(c > 0) % if returns an array that isn't empty, then some elements are on the right side
cat2 = isempty(cat);
if cat2 ==1
disp('fuck yeah, something exists on the right side')
end
My only concern is based on the output of the POLE function (which I’m not clear about) I don’t see where it captures both axes (I would have assumed an n –by- 2 axis). If you give an example so I can run it through, I could probably figure the output (as I’m at work, don’t have time to figure it out; Matlab documentation is usually nice and gives you some examples, but this one is pretty sparton).
The second problem you have is one of logic. You have
(a)some ELSEIF statements in there
(b) You are comparing an vector/array/whatever to a 1x1 constant
The elseif is problematic because you are saying "quit execution of the rest of the loop once the condition is met"
Try this to understand the difference:
Code:
cat = 5
if cat > 1
print('fuck yeah!')
end
if cat > 2
print('fuck yeah!x2')
now try
Code:
if cat > 1
print('fuck yeah!')
elseif cat > 2
print('fuck yeah!x2')
end
Going to (b), try this:
Code:
c=[ -1 0 1]
if c >0
disp('cat')
end
What do you think will happen?
Resolve the three issues I said
(a) Understanding the output of the functions you call
(b) Knowing how to use your case statements
(c) Thinking about what it means to compare a constant to an array using > , < or ==
and you will figure it out.
edit:
If you post an example I could probably help you out more.