s = "Matlab rocks";
fprintf (s(3));
Index exceeds the number of array elements. Index must not exceed 1.
Error (line 2)
fprintf (s(3));

回答 (1 件)

KSSV
KSSV 2022 年 3 月 24 日

0 投票

s = "Matlab rocks";
fprintf ('%s\n',s);
Matlab rocks

4 件のコメント

Kyara Christelle Riguerra
Kyara Christelle Riguerra 2022 年 3 月 24 日
What if I want to get the 3rd character in the string? Thanks.
KSSV
KSSV 2022 年 3 月 24 日
s = "Matlab rocks";
s{1}(3)
ans = 't'
KSSV
KSSV 2022 年 3 月 24 日
s = "Matlab rocks";
sc = char(s) ;
sc(3)
ans = 't'
Kyara Christelle Riguerra
Kyara Christelle Riguerra 2022 年 3 月 24 日
Thanks!

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by