myCSVread - ca = fread(fid) C = x = 1 y = 1 for i =...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 %Write a function called myCSVread which takes in a filename and returns a %cell array containing the doubles and chars from the file. Each value %will be seperated by commas. This function should work as the reverse of %myCSVwrite. %Hint: str2num returns an empty vector if there are character's in a string %that cannot be converted to a double. function output = myCSVread(filename) fid = fopen(filename,'r')
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ca = fread(fid) C = x = 1 y = 1 for i = 1:length(ca) if ca(i) == 44 y = y + 1 C = elseif ca(i) == 10 x = x + 1 C = y = 1 else C = [C, ca(i)] output{x,y} = char(C) end end [rows, cols] = size(output) for x = 1:rows for y = 1:cols if isempty(str2num(output{x,y})) == 1 output{x,y} = output{x,y} else output{x,y} = str2num(output{x,y}) end end end fclose(fid)...
View Full Document

This note was uploaded on 07/06/2009 for the course CS 1371 taught by Professor Stallworth during the Fall '08 term at Georgia Institute of Technology.

Ask a homework question - tutors are online