Why do I receive an error when I run this code?

Why do I receive an error when I run this code?
sys=tf([1],[1 1],'InputDelay',2)
sysd=c2d(sys,0.5)
[num,den]=tfdata(sysd)
num=num2str(num{:})
den=num2str(den{:})
num=poly2sym(num,z)
den=poly2sym(den,z)
num=char(num)
den=char(den)

 채택된 답변

Paulo Silva
Paulo Silva 2011년 6월 9일

1 개 추천

Bad use of the poly2sym function, you give a string for the first argument but the function expects one array.
Also the z should be like this 'z'
doc poly2sym
Just a tip: num{:} gives you one array, that array can be used by poly2sym
sys=tf([1],[1 1],'InputDelay',2)
sysd=c2d(sys,0.5)
[num,den]=tfdata(sysd)
num=vpa(poly2sym(num{:},'z'),4)
den=vpa(poly2sym(den{:},'z'),4)
nums=char(num)
dens=char(den)
There were some errors, I had to edit the answer several times but I think that now it's all working.

댓글 수: 5

sadel
sadel 2011년 6월 9일
I removed the num2str function and I receive a very big result
num =
1772028374299899/4503599627370496
den =
z - 2731571253070597/4503599627370496
Why?
Because it's the exact value.
you can see the same behavior in the documentation example
doc poly2sym
ok I fixed the code again, no more big and precise values, happy now?
sadel
sadel 2011년 6월 9일
hahaha yes, thank you very much!!!!

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

추가 답변 (1개)

Julián Francisco
Julián Francisco 2011년 6월 9일

0 개 추천

My Matlab program says that you have not defined the variable z.

카테고리

도움말 센터File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2011년 6월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by