remove end comma

답변 (1개)

Walter Roberson
Walter Roberson 2011년 11월 7일

1 개 추천

Do you really have the apostrophes there, or are you just seeing the way that MATLAB displays a string that is stored in a cell array?
If the apostrophes are really there, then
B = A(2:end-1);

댓글 수: 4

huda nawaf
huda nawaf 2011년 11월 7일
I don't know why c5 return
'2005-04-22', when use c5=c4(2:end-1), I got :Empty cell array: 1-by-0
this code:
f=fopen('d:\matlab7\work\mv_0000002.txt','r');
c = textscan(f,'%f %f %s','Delimiter',',','headerLines',1);
c1=c{1};
c2=c{2}; c3=c{3};
for g=1:1%length(c3)
c4=c3(g);
c5=c4(1:end);
str=datestr(c4);
c33(g) = datenum('str', 'dd-mmm-yyyy')
end
thanks
Walter Roberson
Walter Roberson 2011년 11월 7일
You should consider using 'CollectOutput', 1 as a textscan() parameter.
When you have a %s parameter, because the length of each string might be different, each string is returned in its own cell array element. c(3) is a cell array of cell arrays, and c{3} is a cell array, making your c3 a cell array. c3(g) is then a 1x1 cell array, so your c4 is a 1x1 cell array. And that's why it displays with the apostrophes, exactly as I foretold at the beginning of my answer.
You want c4 = c3{g}
and then do not bother removing anything from that string. Just pass c4 to datenum as the first parameter:
c33(g) = datenum(c4, 'dd-mmm-yyyy');
Or you could just omit the entire loop over g, using instead
c33 = datenum(c{3}, 'dd-mmm-yyyy');
huda nawaf
huda nawaf 2011년 11월 7일
I got this error:
??? DATENUM failed.
Failed on converting date string to date number.
>> that because datenum work with datestr y which convert the date into 07-Nov-2011.then use datenum
thaks
Walter Roberson
Walter Roberson 2011년 11월 7일
Ah, you changed in and out of date formats for no apparent reason.
This should do the conversion in one step:
c33 = datenum(c{3}, 'yyyy-mm-dd');

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

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

질문:

2011년 11월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by