asked in 電腦與網際網路程式設計 · 2 decades ago

matlab 印出矩陣的問題

fprintf('A=%?',X);

?中要填什麼才會印出一矩陣

2 Answers

Rating
  • Anonymous
    2 decades ago
    Favorite Answer

    你在格式化輸出有以下格式可以選擇

    Specifier Description

    %c ------- Single character

    %d ------- Decimal notation (signed)

    %e -------- Exponential notation (using a lowercase e as in 3.1415e+00)

    %E ------- Exponential notation (using an uppercase E as in 3.1415E+00)

    %f -------- Fixed-point notation

    %g -------- The more compact of %e or %f, as defined in [2]. Insignificant zeros do not print.

    %G -------- Same as %g, but using an uppercase E

    %i --------- Decimal notation (signed)

    %o -------- Octal notation (unsigned)

    %s -------- String of characters

    %u --------- Decimal notation (unsigned)

    %x --------- Hexadecimal notation (using lowercase letters a-f)

    %X --------- Hexadecimal notation (using uppercase letters A-F)

    你給一個矩陣

    例如一個3*3矩陣

    a=[1 2 3;4 5 6;7 8 9];

    你可以利用

    fprintf('a=%?',a)

    將 ? 填入上面可用的格式

    所有的格式都無法達成你的要求

    印出一矩陣

    可以利用非格式化輸出

    disp(a)

    就可以得到一個矩陣

    >> disp(a)

    1 2 3

    4 5 6

    7 8 9

    或者乾脆直接鍵入

    a

    也可以得到一個矩陣

    a =

    1 2 3

    4 5 6

    7 8 9

    Source(s):
  • 豬皮
    Lv 5
    2 decades ago

    如果是要印出X矩陣,直接打X就可以印出矩陣了,不需要再用到fprintf函數。

Still have questions? Get your answers by asking now.