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

2 次查看(过去 30 天)
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.

回答(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 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by