From: Nicholas Kinar on 29 May 2010 19:24 > I'd suggest lookling at the file w/ the import wizard first; if it > handles it, that's probably the least intensive from user standpoint. > > textscan() is more flexible than textread() Specifically, the > 'collectoutputs' option will place the numerics in an array which is > convenient for plotting. > > datenum() and friends works on cell arrays, too... > > -- Thank you once again for your response, dpb; this is greatly appreciated. The import wizard seems to handle the file correctly, and in Matlab R2010a, I'm also given the ability to generate code to load the file: fileToRead = 'test.csv'; DELIMITER = ','; HEADERLINES = 3; % Import the file newData = importdata(fileToRead, DELIMITER, HEADERLINES); % Create new variables in the base workspace from those fields. vars = fieldnames(newData); for i = 1:length(vars) assignin('base', vars{i}, newData.(vars{i})); end This code creates the following in the workspace: DELIMITER, HEADERLINES, data, fileToRead, i, newData, textdata, vars Note that "textdata" is not listed in the code, but Matlab creates this variable in the workspace. >> size(textdata) ans = 6840 72 Then how would I deal with the "NAN" elements in "textdata" and convert the cell array to numerical values? Suppose that I want to grab the first and 66th column of this cell array, remove the "NAN" elements, and then convert the matrix all to a value such as double? However, this has given me yet another idea. Perhaps I could write a MEX file in C. The MEX program would parse the data as I please and then return it to Matlab. To me, this seems much easier than trying to work with all of these cell arrays. Nicholas
From: Nicholas Kinar on 29 May 2010 19:27 > > 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. Nicholas
From: Nicholas Kinar on 29 May 2010 19:36 > > Then how would I deal with the "NAN" elements in "textdata" and convert > the cell array to numerical values? Suppose that I want to grab the > first and 66th column of this cell array, remove the "NAN" elements, and > then convert the matrix all to a value such as double? Perhaps "remove" is not the right operation. I might want to convert "NAN" to "NaN" so that Matlab can still plot the data. Nicholas
From: TideMan on 29 May 2010 21:50 On May 30, 11:27 am, 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. > > Nicholas Oh dear, now you've torn it. Mentioning Fortran and Rune in the same sentence is like pouring gasoline on a fire...................
From: dpb on 29 May 2010 21:48 Nicholas Kinar wrote: > >> >> Then how would I deal with the "NAN" elements in "textdata" and convert >> the cell array to numerical values? Suppose that I want to grab the >> first and 66th column of this cell array, remove the "NAN" elements, and >> then convert the matrix all to a value such as double? > > Perhaps "remove" is not the right operation. I might want to convert > "NAN" to "NaN" so that Matlab can still plot the data. 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] --
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 |