Preventing factor oursite matrix when using the disp() function.

조회 수: 1 (최근 30일)
David Cole
David Cole 2024년 11월 12일
댓글: Walter Roberson 2024년 11월 12일
How do I prevent the 1.0e+02 factor from being displayed. I want the complete number to be included inside the matrix.

답변 (2개)

Voss
Voss 2024년 11월 12일

See format.


Umar
Umar 2024년 11월 12일

Hi @David Cole,

I do agree with @Voss comments. In MATLAB, when the numbers in a matrix are very large or very small, the default display format may switch to scientific notation. To ensure that the complete numbers are displayed without this notation, you can change the display format using the format command. Specifically, using format long will allow MATLAB to display more digits and avoid scientific notation for most cases. Here is how you can modify your code to achieve the desired output:

% Define the admittance values
Y11 = 1/(0.21) + 1/(0.009i);
Y12 = 1/(0.0091);
Y13 = 0;
Y21 = 1/(0.0091);
Y22 = 1/(0.0091) + 1/(0.027i);
Y23 = 1/(0.0271);
Y31 = 0;
Y32 = 1/(0.027i);
Y33 = 1/(0.21) + 1/(0.027i);
% Create the Ybus matrix
Ybus = [Y11, Y12, Y13; Y21, Y22, Y23; Y31, Y32, Y33];
% Set the display format to long to avoid scientific notation
format long;
% Display the Ybus matrix
disp(Ybus);

Please see attached.

The admittance values are calculated using complex numbers, where i represents the imaginary unit. The matrix Ybus is constructed using the previously defined admittance values. The command format long is used to change the output format to long, which displays more digits and reduces the likelihood of scientific notation. Finally, the disp function is called to output the Ybus matrix.

Hope this helps.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by