remove end comma

Answers (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 Comments

huda nawaf
huda nawaf on 7 Nov 2011
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
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 on 7 Nov 2011
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
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');

Sign in to comment.

Categories

Tags

Asked:

on 7 Nov 2011

Community Treasure Hunt

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

Start Hunting!