Print results using fprintf in required format

Hi.
I have a matrix X = [3 2 5].
I want to display the results as
X1 = 3
X2 = 2
X3 = 5
I tried using
X= [3 2 5]
for(i=1:3)
t = i;
fprintf('\nThe value of X%0.0f ',i,' = %0.1f',X(t))
end
but results are ambiguous.
Kindly help with the correct syntax.

3 件のコメント

virpartap singh
virpartap singh 2015 年 11 月 17 日
try this out x1=x(1,1); display (x1) x2=x(1,2); display (x2) x3=x(1,3); display (x3);
Prafulla Kumar Ambekar
Prafulla Kumar Ambekar 2015 年 11 月 17 日
Thank you
Naeem Khan
Naeem Khan 2018 年 1 月 17 日
try out this: X= [3 2 5] for(i=1:3) t = i; fprintf('\nThe value of X%0.0f',i) fprintf('=%0.0f',X(t)) end

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

 採用された回答

Thorsten
Thorsten 2015 年 11 月 17 日
編集済み: Thorsten 2015 年 11 月 17 日

0 投票

fprintf accepts only a single format string:
for i = 1:numel(X), fprintf('The value of X%d = %0.1f\n',i, X(i)),end

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEntering Commands についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by