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.
s = "Matlab rocks";
s{1}(3)
ans = 't'
s = "Matlab rocks";
sc = char(s) ;
sc(3)
ans = 't'
Kyara Christelle Riguerra
Kyara Christelle Riguerra 2022년 3월 24일
Thanks!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2022년 3월 24일

댓글:

2022년 3월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by