how can we use for loop to get index of matrix and letters ?

조회 수: 1 (최근 30일)
Manav Divekar
Manav Divekar 2021년 11월 11일
답변: Prince Kumar 2021년 11월 23일
If i have a matrix [1 2] or [2 1] and word 'orange' how can i use position mentioned in matrix to extract the letters in that position. i want try using for loop.
  댓글 수: 2
Jan
Jan 2021년 11월 11일
The question is very basic. Did you read the "Getting started" chapters of the documentation already and processed Matlab's Onramp? This would help you efficiently to solve such problems.

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

답변 (1개)

Prince Kumar
Prince Kumar 2021년 11월 23일
Hi Manav,
You can do it via the following code:
s = 'orange';
v = [1 2 5];
for i=1:numel(v)
fprintf("Char at %d is %s\n", v(i), s(v(i)));
end

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by