필터 지우기
필터 지우기

Reverse a string using a FOR loop

조회 수: 1 (최근 30일)
Susana Salinas
Susana Salinas 2020년 2월 12일
댓글: Susana Salinas 2020년 2월 12일
So I have this string array.
fair4 =
9×1 string array
"The"
"reyen"
"in"
"Speyen"
"steyes"
"meyenly"
"in"
"the"
"pleyen."
I want to write a for loop to reverse the order of the letter in words in fair4 without using the revrese function. So "The" would be "eht."
I have this code but I don't know how to fix it.
fair5c= fair4;
summer= char(fair4);
summer= string(summer(end:-1:1));
yellow= []
for i= 1:length(summer)
yellow= [yellow,summer(end-i+1)];
end
fair5c= string(yellow)
  댓글 수: 1
Susana Salinas
Susana Salinas 2020년 2월 12일
no puedo usar eso! necesito usar el for loop para lo que requiere mi tarea :(

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

답변 (1개)

David Hill
David Hill 2020년 2월 12일
count=1;
for k=length(fair4):-1:1
fair5(count)=fair4(k);
count=count+1;
end
fair5=fair5';
  댓글 수: 2
James Tursa
James Tursa 2020년 2월 12일
This is homework.
Susana Salinas
Susana Salinas 2020년 2월 12일
Sorry for the confusion-- so I meant the letters of the words would be reversed! So "the" would be "eht."

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by