Comining the values and merging

23 Ansichten (letzte 30 Tage)
kash
kash am 8 Aug. 2012
A=
'' 'c0' 'c1' 'c2' 'c3' 'c4' 'c5' 'c6'
'yar12' 'hi' 'hello' 'hi' 'hello' 'hi' 'hi' 'hi'
'yar13' hello' 'hi' 'hi' 'hello' 'hi' 'hi' 'hi'
'yar14' 'hi' 'hi' 'hi' 'hello' 'hello' 'hello' 'hi'
'yar15' 'hello' 'hi' 'hi' 'hi' 'hi' 'hi' 'hello'
'yar16' 'hello' 'hi' 'hi' 'hello' 'hello' 'hello'
'yar17' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' hello'
I need to combine intervals
c0c1c2c3
c1c2c3c4
c2c3c4c5
c3c4c5c6
so for example for yar12
'c0c1c2c3' 'c1c2c3c4' 'c2c3c4c5' 'c3c4c5c6'
'yar12' 'hihellohihello' 'hellohihellohi' 'hihellohihi' 'hellohihihi'
like this i need for all values from yar13 to yar130(for sample i have posted till yar17)
please help

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 8 Aug. 2012
A= {'' 'c0' 'c1' 'c2' 'c3' 'c4' 'c5' 'c6'
'yar12' 'hi' 'hello' 'hi' 'hello' 'hi' 'hi' 'hi'
'yar13' 'hello' 'hi' 'hi' 'hello' 'hi' 'hi' 'hi'
'yar14' 'hi' 'hi' 'hi' 'hello' 'hello' 'hello' 'hi'
'yar15' 'hello' 'hi' 'hi' 'hi' 'hi' 'hi' 'hello'
'yar16' 'hello' 'hi' 'hi' 'hello' 'hello' 'hello' 'hello'
'yar17' 'hi' 'hi' 'hi' 'hi' 'hi' 'hi' 'hello' };
A2 = num2cell(A,1);
idx = hankel(2:5,5:8);
out = [A2(:,1),arrayfun(@(i1)strcat(A2{idx(i1,:)}),1:size(idx,1),'un',0)];
out = [out{:}];

Weitere Antworten (1)

Oleg Komarov
Oleg Komarov am 8 Aug. 2012
B = num2cell(A,1);
B = [B{:,1} strcat(B{2:5}) strcat(B{3:6}) strcat(B{4:7}) strcat(B{5:8})];

Kategorien

Mehr zu Clocks and Timers finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by