Filter löschen
Filter löschen

changing the string "JF 2009" to two seperate strings "J 2009" " F2009" (reposted)

2 Ansichten (letzte 30 Tage)
Dear all I have the following cell matrix
A={
1 'SLO' ' '
1 'SLO' ' '
1 'SLO' 'JF 2009'
1 'SLO' 'MA 2009'
1 'SLO' 'MJ 2009'
1 'SLO' 'JA 2009'
1 'SLO' 'SO 2009'
1 'SLO' 'ND 2009'
1 'SLO' 'JF 2010'
1 'SLO' 'MA 2010'
1 'SLO' 'MJ 2010'
1 'SLO' 'JA 2010'
1 'SLO' 'SO 2010'
1 'SLO' 'ND 2010'
1 'SLO' 'JF 2011'
1 'SLO' 'MA 2011'
1 'SLO' 'MJ 2011'
1 'SLO' 'JA 2011'
2 'SLO' ' '
2 'SLO' ' '
2 'SLO' 'JF 2009'
2 'SLO' 'MA 2009'
2 'SLO' 'MJ 2009'
2 'SLO' 'JA 2009'
2 'SLO' 'SO 2009'
2 'SLO' 'ND 2009'
2 'SLO' 'JF 2010'
2 'SLO' 'MA 2010'
2 'SLO' 'MJ 2010'
2 'SLO' 'JA 2010'
2 'SLO' 'SO 2010'
2 'SLO' 'ND 2010'
2 'SLO' 'JF 2011'
2 'SLO' 'MA 2011'
2 'SLO' 'MJ 2011'
2 'SLO' 'JA 2011'
}
As you can see I have bimontly data. I want to modify the last column so as to have months like
Amodified={
1 'SLO' ' '
1 'SLO' ' '
1 'SLO' 'J 2009'
1 'SLO' 'F 2009'
1 'SLO' 'M 2009'
1 'SLO' 'A 2009'
1 'SLO' 'M 2009'
1 'SLO' 'J 2009'
1 'SLO' 'J 2010' }
and so forth
The previous answers were correct and I thank these guys. Yet their code can be applied for small number of individuals. In my case I have 30000 individuals.
Could you please help me?
thanks
  3 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 26 Jul. 2012
from where are your importing your data, excell? are they from workspace?
Azzi Abdelmalek
Azzi Abdelmalek am 26 Jul. 2012
i tryed with a 30000x1 array , and it works!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 26 Jul. 2012
Bearbeitet: Andrei Bobrov am 26 Jul. 2012
Amodified = [];
for jj = 1:size(A,1)
if ~strcmp(A{jj,3},' ')
z = [A([jj,jj],1:2),...
[{[A{jj,3}(1),A{jj,3}(3:end)]};...
{[A{jj,3}(2),A{jj,3}(3:end)]}]];
else
z = A([jj],:);
end
Amodified = [Amodified;z];
end

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 26 Jul. 2012
Bearbeitet: Azzi Abdelmalek am 26 Jul. 2012
%i tryed this code to test a 30000x3 array
for k=1:10;A=[A;A];end % A is now a 36864x3
n=size(A,1)
c1=num2cell([1:n]')
a=[c1 A]
b=sortrows(a,4)
B=b(:,4)
d=max(find(cellfun(@(x) length(x)>2,B)==0))
C=b(d+1:end,:)
n1=size(C,1)
ind1=1:2:2*n1-1;ind2=2:2:2*n1,C1=C;C2=C;
C1(:,4)=cellfun(@(x) strtrim(regexprep(x,x(1),'')),C(:,4),'UniformOutput',false)
C2(:,4)=cellfun(@(x) strtrim(regexprep(x,x(2),'')),C(:,4),'UniformOutput',false)
D=cell(n1*2,4); D(ind1,:)=C2; D(ind2,:)=C1;
E=sortrows([b(1:d,:) ; D],1);
Result=E(:,2:4)
% the program works % depending on the performance of your computer, it takes maby longer,

Kategorien

Mehr zu Line Plots 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