필터 지우기
필터 지우기

Need help with the code.

조회 수: 1 (최근 30일)
Manav Divekar
Manav Divekar 2021년 11월 12일
답변: DGM 2021년 11월 12일
i want to swaps characters of s as specified by the indices present in the pairs variable. pairs is a 2-column matrix, where on each row, i have given the positions of the two characters that need to swap. eg s = orange & pairs = [1 2]. out expected is roange. what changes you recommend in this code.
function [arr] = shuffletext ( pairs, s)
a = 0;
b = 0;
for i = 1:numel(s)
for j = pairs
s(i) = a;
a = b;
b = s(i);
end
end
arr = b;
Still its not showing any output just a blank if i call the function
using: disp( shuffletext( [1 2], 'orange') )
Output
>> disp( shuffletext( [1 2], 'orange') )
>>

답변 (1개)

DGM
DGM 2021년 11월 12일
Try this.
shuffletext2([1 2; 3 4; 5 6], 'orange')
ans = 'ronaeg'
function [intext] = shuffletext2(pairs,intext)
for p = 1:size(pairs,1)
intext(pairs(p,:)) = intext(fliplr(pairs(p,:)));
end
end

카테고리

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

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by