Double output using disp()

19 ビュー (過去 30 日間)
Mughees Asif
Mughees Asif 2019 年 2 月 25 日
コメント済み: Steve Kulakowski 2019 年 2 月 25 日
The following code gives two outputs when I have only one disp() command at the end:
characteristic = [1.000 2.2500 2.5002];
b = HurwitzMatrix(characteristic);
function [characteristic] = HurwitzMatrix(characteristic)
number = length(characteristic)-1;
D = zeros(number,number);
X = [zeros(1, number-2),characteristic zeros(1, number-1)];
for r = 1:number
E(r,:) = X(3+number-2-r:2:3+number-2-r+2*(number-1));
disp('Hurwitz Matrix')
disp(E)
end
end
The output is as follows:
Hurwitz Matrix
2.2500 0
Hurwitz Matrix
2.2500 0
1.0000 2.5002
Any suggestions to ensure only the bottom matrix (2x2) is displayed with the title would be helpful! Thank you.

採用された回答

Steve Kulakowski
Steve Kulakowski 2019 年 2 月 25 日
Try moving the "disp" statement out side of the for loop. So the last four lines of your code look like this.
end
disp('Hurwitz Matrix')
disp(E)
end
  2 件のコメント
Mughees Asif
Mughees Asif 2019 年 2 月 25 日
Thank you.
Steve Kulakowski
Steve Kulakowski 2019 年 2 月 25 日
You're welcom.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by