Created
March 8, 2015 20:53
-
-
Save sash13/8c73e963223c8b6d2cc8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data = read_mixed_csv('tube19.csv', ','); | |
| dt = datenum(strcat(data(:,1), {' '}, data(:,2)), 'dd.mm.yyyy HH:MM'); | |
| M = [dt str2double(data(:,3))]; | |
| plot(M(:,1), M(:,2)) | |
| NumTicks = 10; | |
| L = get(gca,'XLim'); | |
| set(gca,'XTick',linspace(L(1),L(2),NumTicks)) | |
| datetick('x',19,'keeplimits', 'keepticks') | |
| % use this: minX = datenum(2009, 12, 31) for scale | |
| %axis([min(M(:,1)) max(M(:,1)) min(M(:,2))*1.1 max(M(:,2))*1.2]) | |
| grid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function lineArray = read_mixed_csv(fileName,delimiter) | |
| fid = fopen(fileName,'r'); %# Open the file | |
| lineArray = cell(100,1); %# Preallocate a cell array (ideally slightly | |
| %# larger than is needed) | |
| lineIndex = 1; %# Index of cell to place the next line in | |
| nextLine = fgetl(fid); %# Read the first line from the file | |
| while ~isequal(nextLine,-1) %# Loop while not at the end of the file | |
| lineArray{lineIndex} = nextLine; %# Add the line to the cell array | |
| lineIndex = lineIndex+1; %# Increment the line index | |
| nextLine = fgetl(fid); %# Read the next line from the file | |
| end | |
| fclose(fid); %# Close the file | |
| lineArray = lineArray(1:lineIndex-1); %# Remove empty cells, if needed | |
| for iLine = 1:lineIndex-1 %# Loop over lines | |
| lineData = textscan(lineArray{iLine},'%s',... %# Read strings | |
| 'Delimiter',delimiter); | |
| lineData = lineData{1}; %# Remove cell encapsulation | |
| if strcmp(lineArray{iLine}(end),delimiter) %# Account for when the line | |
| lineData{end+1} = ''; %# ends with a delimiter | |
| end | |
| lineArray(iLine,1:numel(lineData)) = lineData; %# Overwrite line data | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment