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

2 visualizaciones (últimos 30 días)
Manav Divekar
Manav Divekar el 11 de Nov. de 2021
Respondida: Prince Kumar el 23 de Nov. de 2021
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 comentarios
Jan
Jan el 11 de Nov. de 2021
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.

Iniciar sesión para comentar.

Respuestas (1)

Prince Kumar
Prince Kumar el 23 de Nov. de 2021
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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by