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

Réponses (1)

KSSV
KSSV le 24 Mar 2022

0 votes

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

4 commentaires

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

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by