How do i read a string with a for loop.
23 次查看(过去 30 天)
显示 更早的评论
I need to read a string with a for loop and evaluate it s characters by threes.
say i have some string input = aaaaabaacaadaae....
i need to cut this into 3 piece sections, then run them through a switch statement.
switch (string)
case(aaa) x=1 case(aab)=2
and so on, then terminate when i got to the end of the string?
i have the switch statement already i just need to figure out how to evalute the string witha for loop.
0 个评论
回答(1 个)
Iman Ansari
2013-4-12
Hi
input = 'aaaaabaacaadaae';
n=1;
for i=1:3:size(input,2)
New{n}=input(i:min(i+2,size(input,2)));
n=n+1;
end
4 个评论
Iman Ansari
2013-4-12
编辑:Iman Ansari
2013-4-12
With array it's easier to index it's contents:
New{3}
New{5}
But without cell array number of your variables increase:
x1=input(1:3)
x2=input(4:6)
x3=input(7:9)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!