From: Jon on 1 Jun 2010 05:38 Hopefully I can get an answer to this. I've been trying to figure this out for a few hours. I simply need to split up a vector of strings like '100518' into a matrix of vectors '10', '05', and '18'. My code is this: data1sd = textscan(fid,'%s %s %n %n %n %n %n %n','Delimiter','\t'); fclose(fid); [sdfiletime] = data1sd{:,1} sdfileyear = str2double(sdfiletime(:,1:2)) sdfilemonth = str2double(sdfiletime(:,3:4)) sdfileday = str2double(sdfiletime(:,5:6)) I get ??? Index exceeds matrix dimensions. For some reason sdfiletime is a vector of strings with a size of 1! I don't understand why this is the case when a few lines earlier in the code I was able to do this underscores = strfind(locname, '_'); filetime = locname((underscores(1)+1):(underscores(2)-1)); fileyear = str2double(filetime(1:2)); filemonth = str2double(filetime(3:4)); fileday = str2double(filetime(5:6)); I've been going at this too long.
From: us on 1 Jun 2010 05:47 "Jon " <anti_pope.remove.this(a)hotmail.com> wrote in message <hu2kdr$lgr$1(a)fred.mathworks.com>... > Hopefully I can get an answer to this. I've been trying to figure this out for a few hours. I simply need to split up a vector of strings like '100518' into a matrix of vectors '10', '05', and '18'. My code is this: > > data1sd = textscan(fid,'%s %s %n %n %n %n %n %n','Delimiter','\t'); > fclose(fid); > > [sdfiletime] = data1sd{:,1} > > sdfileyear = str2double(sdfiletime(:,1:2)) > sdfilemonth = str2double(sdfiletime(:,3:4)) > sdfileday = str2double(sdfiletime(:,5:6)) > > I get ??? Index exceeds matrix dimensions. For some reason sdfiletime is a vector of strings with a size of 1! I don't understand why this is the case when a few lines earlier in the code I was able to do this > > underscores = strfind(locname, '_'); > filetime = locname((underscores(1)+1):(underscores(2)-1)); > fileyear = str2double(filetime(1:2)); > filemonth = str2double(filetime(3:4)); > fileday = str2double(filetime(5:6)); > > I've been going at this too long. show two or three data entries of data1sd % and data1sd{1} us
From: Jon on 1 Jun 2010 05:59 data1sd = Columns 1 through 6 {691x1 cell} {691x1 cell} [691x1 double] [691x1 double] [691x1 double] [691x1 double] Columns 7 through 8 [691x1 double] [691x1 double] ans = '100518' '100518' '100518' '100518' '100518' Thanks for looking at this. "us " <us(a)neurol.unizh.ch> wrote in message <hu2kun$ps1$1(a)fred.mathworks.com>... > "Jon " <anti_pope.remove.this(a)hotmail.com> wrote in message <hu2kdr$lgr$1(a)fred.mathworks.com>... > > Hopefully I can get an answer to this. I've been trying to figure this out for a few hours. I simply need to split up a vector of strings like '100518' into a matrix of vectors '10', '05', and '18'. My code is this: > > > > data1sd = textscan(fid,'%s %s %n %n %n %n %n %n','Delimiter','\t'); > > fclose(fid); > > > > [sdfiletime] = data1sd{:,1} > > > > sdfileyear = str2double(sdfiletime(:,1:2)) > > sdfilemonth = str2double(sdfiletime(:,3:4)) > > sdfileday = str2double(sdfiletime(:,5:6)) > > > > I get ??? Index exceeds matrix dimensions. For some reason sdfiletime is a vector of strings with a size of 1! I don't understand why this is the case when a few lines earlier in the code I was able to do this > > > > underscores = strfind(locname, '_'); > > filetime = locname((underscores(1)+1):(underscores(2)-1)); > > fileyear = str2double(filetime(1:2)); > > filemonth = str2double(filetime(3:4)); > > fileday = str2double(filetime(5:6)); > > > > I've been going at this too long. > > show two or three data entries of > > data1sd > % and > data1sd{1} > > us
From: Pekka Kumpulainen on 1 Jun 2010 06:01 "Jon " <anti_pope.remove.this(a)hotmail.com> wrote in message <hu2kdr$lgr$1(a)fred.mathworks.com>... > Hopefully I can get an answer to this. I've been trying to figure this out for a few hours. I simply need to split up a vector of strings like '100518' into a matrix of vectors '10', '05', and '18'. My code is this: > > data1sd = textscan(fid,'%s %s %n %n %n %n %n %n','Delimiter','\t'); > fclose(fid); > > [sdfiletime] = data1sd{:,1} > > sdfileyear = str2double(sdfiletime(:,1:2)) > sdfilemonth = str2double(sdfiletime(:,3:4)) > sdfileday = str2double(sdfiletime(:,5:6)) > > I get ??? Index exceeds matrix dimensions. For some reason sdfiletime is a vector of strings with a size of 1! I don't understand why this is the case when a few lines earlier in the code I was able to do this > > underscores = strfind(locname, '_'); > filetime = locname((underscores(1)+1):(underscores(2)-1)); > fileyear = str2double(filetime(1:2)); > filemonth = str2double(filetime(3:4)); > fileday = str2double(filetime(5:6)); > > I've been going at this too long. sdfiletime is probably a one column cell array so you can not index into second column like in sdfiletime(:,1:2). This _should_ work if the file content is as I assume: sdfileyear =str2double(cellfun(@(x) x(1:2),sdfiletime,'UniformOutput', false)); filemonth = str2double(cellfun(@(x) x(3:4),sdfiletime,'UniformOutput', false)); fileday = str2double(cellfun(@(x) x(5:6),sdfiletime,'UniformOutput', false)); If the date is always like that you could also read the date directly in parts of 2 numbers: replace the first %s in textscan with '%2f %2f %2f Now sdfileyear = data1sd{1}; filemonth = data1sd{2}; etc. hth
From: Jon on 1 Jun 2010 06:13 Replacing the first %s in textscan with '%2f %2f %2f worked brilliantly! I had no idea you could do that. Thank you. The instruction manual makes it seem like %2f would just read 2 digits and then skip over the rest of it. I can't believe how much time I've wasted on this. "Pekka Kumpulainen" <pekka.nospam.kumpulainen(a)tut.please.fi> wrote in message <hu2lp2$kcf$1(a)fred.mathworks.com>... > "Jon " <anti_pope.remove.this(a)hotmail.com> wrote in message <hu2kdr$lgr$1(a)fred.mathworks.com>... > > Hopefully I can get an answer to this. I've been trying to figure this out for a few hours. I simply need to split up a vector of strings like '100518' into a matrix of vectors '10', '05', and '18'. My code is this: > > > > data1sd = textscan(fid,'%s %s %n %n %n %n %n %n','Delimiter','\t'); > > fclose(fid); > > > > [sdfiletime] = data1sd{:,1} > > > > sdfileyear = str2double(sdfiletime(:,1:2)) > > sdfilemonth = str2double(sdfiletime(:,3:4)) > > sdfileday = str2double(sdfiletime(:,5:6)) > > > > I get ??? Index exceeds matrix dimensions. For some reason sdfiletime is a vector of strings with a size of 1! I don't understand why this is the case when a few lines earlier in the code I was able to do this > > > > underscores = strfind(locname, '_'); > > filetime = locname((underscores(1)+1):(underscores(2)-1)); > > fileyear = str2double(filetime(1:2)); > > filemonth = str2double(filetime(3:4)); > > fileday = str2double(filetime(5:6)); > > > > I've been going at this too long. > > sdfiletime is probably a one column cell array so you can not index into second column like in sdfiletime(:,1:2). > > This _should_ work if the file content is as I assume: > sdfileyear =str2double(cellfun(@(x) x(1:2),sdfiletime,'UniformOutput', false)); > filemonth = str2double(cellfun(@(x) x(3:4),sdfiletime,'UniformOutput', false)); > fileday = str2double(cellfun(@(x) x(5:6),sdfiletime,'UniformOutput', false)); > > If the date is always like that you could also read the date directly in parts of 2 numbers: replace the first %s in textscan with '%2f %2f %2f > Now > sdfileyear = data1sd{1}; > filemonth = data1sd{2}; > etc. > > hth
|
Next
|
Last
Pages: 1 2 Prev: Matlab's radon function - how to rescale? Next: Requesting code for signature recognition. |