Reading in data using xlsread the raw values are not exactly raw. The cells contain hex data and whenever e is present (2e39) it is converting it to a double as 2.000e+39. Is there anyway to force it to read in as '2e39'? I found were it's being read in xlsreadCOM as rawData = DataRange.Value, I also see that VBA has xlRangeValueXMLSpreadsheet that is supposed to read in the exact value but I'm not sure how to apply that in Matlab. Using Matlab2012a
MATLAB: Stop xlsread converting hex values to double
xlsread
Related Solutions
%read file
filestr = fileread('YourFile.txt');%break it into lines
filebyline = regexp(filestr, '\n', 'split');%remove empty lines
filebyline( cellfun(@isempty,filebyline) ) = [];%split by fields
filebyfield = regexp(filebyline, '\|', 'split');%pad out so each line has the same number of fields
numfields = cellfun(@length, filebyfield);maxfields = max(numfields);fieldpattern = repmat({[]}, 1, maxfields);firstN = @(S,N) S(1:N);filebyfield = cellfun(@(S) firstN([S,fieldpattern], maxfields), filebyfield, 'Uniform', 0);%switch from cell vector of cell vectors into a 2D cell
fieldarray = vertcat(filebyfield{:});
Now to be consistent with your diagram, we have to convert to numeric not column by column but rather item by item: your row #8 column #3 is converted to a number even though it is the only one in the column that is converted. This is unusual and would typically lead to problems further down the road, but it is what you said you wanted.
%convert all fields to numeric
numarray = str2double(fieldarray);%switch to cell array of numbers
outarray = num2cell(numarray);%the places that the strings could not be converted to numbers show up as NaN
conv_failed = isnan(numarray);%replace the failed conversions with the original text in the cells
outarray(conv_failed) = fieldarray(conv_failed);
The first part of this code, leading up to the creation of "fieldarray", can be made much much compact if the maximum number of fields per line is known in advance.
fields_per_line = 73; %for example
fmt = repmat('%s',1,fields_per_line);fid = fopen('YourTextFile', 'rt');filebycolumn = textscan(fid, fmt, 'Delimiter', '|');fclose(fid);fieldarray = horzcat(filebycolumn{:});
jpg images are binary images, but textread() is for reading text files.
Does the .dat file perhaps contain the names of the images rather than the images themselves?
There is no standard format for .dat files: it is a suffix used by any program to hold any data. You need to know the internal structure of that particular .dat file in order to work with it. It might be pure text (most .dat files are not).
If you can upload a sample of the file, someone might have a look at it. http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers
Best Answer