From: Nicholas Kinar on 29 May 2010 23:17 > > Oh, the "NAN" is embedded ASCII text; I assumed it was a NaN > > To use cell arrays, you simply dereference them w/ the curly brackets or > if you need to convert to arrays unless later versions of Matlab (I'm at > a fairly old release now) need to use for loops in this version. > > But, textscan() does have the 'group' option I mentioned earlier that > does place things in arrays of same type (but the mixed numeric/text is > an issue it won't handle well, that's true... > > Not knowing precisely the data, something otoo the following trivial > example may help. Matlab isn't C or C++ so it takes a little while > getting used to, perhaps even more so if one is adept in another > language w/ so much to unlearn... :) > > >> c(1)=num2cell(pi); > >> c(3)=num2cell(2); > >> c(2)=cellstr('NAN') > c = > [3.1416] > 'NAN' > [ 2] > >> for idx=1:length(c), if isstr(c{idx}), c(idx)=num2cell(nan);end,end > >> c > c = > [3.1416] > [ NaN] > [ 2] > Yes - thank you very much for that example, dpb! It really helped to point me in the right direction. Okay, here is what I did to convert the character values into numbers: % remove the first three rows of textdata % since this is the header textdata(1:3, :) = []; % create a new vector with only numbers colnum = 66; [rownum,~] = size( textdata ); depth = zeros( rownum, 1); for idx=1:rownum if strcmp(textdata{idx, colnum}, 'NAN') depth( idx ) = nan; else depth( idx ) = str2double( textdata{idx, colnum} ); end end Now one question remains: How do I plot the data, given time/date in the first column? Using Matlab, I extract the column with the timestamp and refer to it as the "time" vector. Now how do I take this cell array and plot it on the x-axis of the plot as shown below? >> time = textdata(:,1); >> class (time) ans = cell >> time{1,1} ans = 01/03/10 10:45 >> time{2,1} ans = 01/03/10 11:00 >> length(time) ans = 6837 >> plot(time, depth) ??? Error using ==> plot Conversion to double from cell is not possible. Once again, thank you very much for your help! Nicholas
From: Nicholas Kinar on 29 May 2010 23:31 > Now one question remains: How do I plot the data, given time/date in the > first column? > > Using Matlab, I extract the column with the timestamp and refer to it as > the "time" vector. Now how do I take this cell array and plot it on the > x-axis of the plot as shown below? > > >> time = textdata(:,1); > >> class (time) > > ans = > > cell > > >> time{1,1} > > ans = > > 01/03/10 10:45 > > >> time{2,1} > > ans = > > 01/03/10 11:00 > > >> length(time) > > ans = > > 6837 > > >> plot(time, depth) > ??? Error using ==> plot > Conversion to double from cell is not possible. > Erm - I think that I might have figured it out myself. What I've done is created the time vector, and converted the string into Matlab's "datenum" format. Then, I've plotted the time vector, but I've also used the datetick function to set the date to a proper display format. time = datenum( textdata(:,1), 'dd/mm/yy HH:MM' ); plot(time, depth); datetick('x', 'mm/dd/yy') Nicholas
From: dpb on 30 May 2010 00:05 Nicholas Kinar wrote: .... > Erm - I think that I might have figured it out myself. What I've done > is created the time vector, and converted the string into Matlab's > "datenum" format. Then, I've plotted the time vector, but I've also > used the datetick function to set the date to a proper display format. > > time = datenum( textdata(:,1), 'dd/mm/yy HH:MM' ); > plot(time, depth); > datetick('x', 'mm/dd/yy') .... Ermmm...yes... :) I mentioned datenum operated on cells earlier, now, didn't I??? Wonder why that was, ya' reckon.... <VBG> --
From: Nicholas Kinar on 30 May 2010 00:39 On 10-05-29 10:05 PM, dpb wrote: > Nicholas Kinar wrote: > ... > >> Erm - I think that I might have figured it out myself. What I've done >> is created the time vector, and converted the string into Matlab's >> "datenum" format. Then, I've plotted the time vector, but I've also >> used the datetick function to set the date to a proper display format. >> >> time = datenum( textdata(:,1), 'dd/mm/yy HH:MM' ); >> plot(time, depth); >> datetick('x', 'mm/dd/yy') > ... > > Ermmm...yes... :) > > I mentioned datenum operated on cells earlier, now, didn't I??? Wonder > why that was, ya' reckon.... <VBG> > > -- Yes - thank you very much for your help, dpb; I was actually responding to the question posed in my previous post. I had to use the datetick() function to create the plot, but you did indeed point me in the right direction with the datenum() function, which generated the vector of dates in the first place. Nicholas
From: Rune Allnor on 30 May 2010 02:52 On 30 Mai, 01:27, Nicholas Kinar <n.ki...(a)usask.ca> wrote: > > By explaining what the problem is? This is a fairly trivial > > exercise... > > > Rune > > Perhaps trivial to you, Rune; I've been using either Fortran/C/C++ for a > long time, but you know more of Matlab than I do at this time. There are a number of matlab functions that emulate the file IO functions from C. Look at FOPEN FCLOSE FREAD FWRITE FSCANF FPRINTF There are some details that differ between C and matlab, but if you know how to do this in C, it will take you no time get the hang of it. The main difference you might want to be aware of, is that matlab's versions have what are termed 'vectorized' versions. These versions scan and import several lines of the file for each call of the function, thus bypassing the matlab interpreter with the intention to save some run-time time. Rune
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Problem with 2D wavelet transform (dwt2) Next: How to make a 3D object out of a surface |