-
Notifications
You must be signed in to change notification settings - Fork 0
Fixes for MATLAB code #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aforren1
wants to merge
2
commits into
master
Choose a base branch
from
aforren1-patch-matlab
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,113 +1,111 @@ | ||
| %load in kinereach data (new cpp code), parsing the header file and the | ||
| %raw data | ||
|
|
||
| function [data,header,varargout] = KRload(varargin) | ||
| %clear all; | ||
| if nargin == 0 | ||
| [fname,fpath] = uigetfile('*.*','Select data file to analyze'); | ||
| else | ||
| fpath = varargin{1}; | ||
| fname = ''; | ||
| end | ||
| function [data, header, filename, filepath] = KRload(filename, filepath) | ||
| % KRLOAD Load in kinereach data (new c++ code), | ||
| % parsing the header file and the raw data. | ||
| % | ||
| % [data, header, filename, filepath] = KRLOAD(filename) | ||
| % The filename is the name of the file, e.g. 'mydata.dat', and | ||
| % the filepath is the full path to the data, e.g. 'C:/Users/data/'. | ||
| % | ||
| % If the filename and path is unspecified, a UI will open to allow | ||
| % manual selection of the file. If just the path is unspecified, the | ||
| % current working directory is assumed (and a warning emitted). | ||
| % | ||
|
|
||
| if nargin == 0 | ||
| [filename, filepath] = uigetfile('*.*', 'Select data file to analyze.'); | ||
| elseif ~exist('filename') | ||
| error('Must provide a filename.'); | ||
| elseif ~exist('filepath') | ||
| warning('Assuming the current path is correct, may fail.'); | ||
| filepath = pwd; | ||
| end | ||
|
|
||
| fid = fopen([fpath fname],'r'); | ||
| fid = fopen([filepath filename], 'r'); | ||
|
|
||
| doloop = 1; | ||
| while (doloop) | ||
| temp = fgetl(fid); | ||
| if strcmp(temp,'--') | ||
| %detect the end of the header | ||
| doloop = true; | ||
| while doloop | ||
| temp = fgetl(fid); | ||
| header.cols = textscan(temp,'%s'); | ||
| header.cols = header.cols{1}; | ||
| fgetl(fid); | ||
| doloop = 0; | ||
| else | ||
| hvals = textscan(temp,'%s %s'); | ||
| if ~isempty(str2num(char(hvals{2}))) | ||
| hvals = textscan(temp,'%s %d'); | ||
| tmp = strrep(char(hvals{1}),':',''); | ||
| eval(sprintf('header.%s = %d;',tmp,hvals{2})); | ||
| if strcmp(temp, '--') | ||
| %detect the end of the header | ||
| temp = fgetl(fid); | ||
| header.cols = textscan(temp, '%s'); | ||
| header.cols = header.cols{1}; | ||
| fgetl(fid); | ||
| doloop = false; | ||
| else | ||
| tmp = strrep(char(hvals{1}),':',''); | ||
| tmp1 = strrep(char(hvals{2}),'.txt',''); | ||
| eval(sprintf('header.%s = ''%s'';',tmp,char(tmp1))); | ||
| hvals = textscan(temp, '%s %s'); | ||
| if ~isempty(str2num(char(hvals{2}))) | ||
| hvals = textscan(temp, '%s %d'); | ||
| tmp = strrep(char(hvals{1}), ':', ''); | ||
| eval(sprintf('header.%s = %d;', tmp, hvals{2})); | ||
| else | ||
| tmp = strrep(char(hvals{1}), ':', ''); | ||
| tmp1 = strrep(char(hvals{2}), '.txt', ''); | ||
| eval(sprintf('header.%s = ''%s'';', tmp, char(tmp1))); | ||
| end | ||
| end | ||
|
|
||
| end | ||
| end | ||
|
|
||
| % %unknown columns, use this code for complete flexiblity | ||
| readstr = ''; | ||
| for a = 1:length(header.cols) | ||
| switch(char(header.cols{a})) | ||
| case {'Device_Num','FakeTime','Time'} | ||
| readstr = [readstr '%d ']; | ||
| case {'HandX','HandY','HandZ','HandYaw','HandPitch','HandRoll','Theta'} | ||
| readstr = [readstr '%f ']; | ||
| case {'StartX','StartY','TargetX','TargetY'} | ||
| readstr = [readstr '%f ']; | ||
| case 'Trace' | ||
| readstr = [readstr '%d ']; | ||
| case 'Keymap' | ||
| readstr = [readstr '%s ']; | ||
| otherwise | ||
| readstr = [readstr '%f ']; | ||
| % unknown columns, use this code for complete flexiblity | ||
| readstr = ''; | ||
| for a = 1:length(header.cols) | ||
| switch(char(header.cols{a})) | ||
| case {'Device_Num', 'FakeTime', 'Time'} | ||
| readstr = [readstr '%d ']; | ||
| case {'HandX', 'HandY', 'HandZ', 'HandYaw', 'HandPitch', 'HandRoll', 'Theta'} | ||
| readstr = [readstr '%f ']; | ||
| case {'StartX', 'StartY', 'TargetX', 'TargetY'} | ||
| readstr = [readstr '%f ']; | ||
| case 'Trace' | ||
| readstr = [readstr '%d ']; | ||
| case 'Keymap' | ||
| readstr = [readstr '%s ']; | ||
| otherwise | ||
| readstr = [readstr '%f ']; | ||
| end | ||
| end | ||
| end | ||
|
|
||
| % %known columns, use this code for proper formatting | ||
| % readstr = '%d %d %f %f %f %f %f %f %f %d'; %devNo, time, x, y, theta, startx, starty, tgtx, tgty, trace | ||
| dvals = textscan(fid, readstr, inf); | ||
|
|
||
| %doloop = 1; | ||
| %while (doloop) | ||
| dvals = textscan(fid,readstr,inf); | ||
| %compute number of birds | ||
| numBirds = length(unique(dvals{1})); | ||
|
|
||
| %compute number of birds | ||
| numBirds = length(unique(dvals{1})); | ||
| for a = 1:numBirds | ||
|
|
||
| for a = 1:numBirds | ||
|
|
||
| %divide data structure into appropriate fields, based on column names | ||
| for b = 1:length(header.cols) | ||
| eval(sprintf('data{%d}.%s = dvals{%d}(%d:%d:end);',a,char(header.cols{b}),b,a,numBirds)); | ||
| end | ||
|
|
||
| if isfield(header,'Sampling_Rate') && isfield(data{a},'HandX') | ||
| data{a}.MakeTime = [0:1:length(data{a}.HandX)-1]'/header.Sampling_Rate*1000; | ||
| elseif isfield(data{a},'HandX') | ||
| data{a}.MakeTime = [0:1:length(data{a}.HandX)-1]'; | ||
| elseif isfield(header,'Sampling_Rate') && isfield(data{a},'StickX') | ||
| data{a}.MakeTime = [0:1:length(data{a}.StickX)-1]'/header.Sampling_Rate*1000; | ||
| elseif isfield(data{a},'StickX') | ||
| data{a}.MakeTime = data{a}.SystemTime-data{a}.SystemTime(1); | ||
| else %unrecognized trial table type | ||
| data{a}.MakeTime = []; | ||
| end | ||
|
|
||
| %identify devide, if possible | ||
| if isfield(data{a},'Device_Num') | ||
| data{a}.Device_Num = unique(data{a}.Device_Num); | ||
| switch data{a}.Device_Num(1) | ||
| case 1 | ||
| data{a}.BirdName = 'Left_Hand'; | ||
| case 2 | ||
| data{a}.BirdName = 'Left_Arm'; | ||
| case 3 | ||
| data{a}.BirdName = 'Right_Hand'; | ||
| case 4 | ||
| data{a}.BirdName = 'Right_Arm'; | ||
| end %end switch | ||
| end %end if | ||
|
|
||
| end %end for loop | ||
| %divide data structure into appropriate fields, based on column names | ||
| for b = 1:length(header.cols) | ||
| eval(sprintf('data{%d}.%s = dvals{%d}(%d:%d:end);', a, char(header.cols{b}), b, a, numBirds)); | ||
| end | ||
|
|
||
| fclose(fid); | ||
| if isfield(header, 'Sampling_Rate') && isfield(data{a},'HandX') | ||
| data{a}.MakeTime = [0:1:length(data{a}.HandX)-1]'/header.Sampling_Rate*1000; | ||
| elseif isfield(data{a}, 'HandX') | ||
| data{a}.MakeTime = [0:1:length(data{a}.HandX) - 1]'; | ||
| elseif isfield(header, 'Sampling_Rate') && isfield(data{a},'StickX') | ||
| data{a}.MakeTime = [0:1:length(data{a}.StickX) - 1]'/header.Sampling_Rate*1000; | ||
| elseif isfield(data{a}, 'StickX') | ||
| data{a}.MakeTime = data{a}.SystemTime - data{a}.SystemTime(1); | ||
| else %unrecognized trial table type | ||
| data{a}.MakeTime = []; | ||
| end | ||
|
|
||
| if nargout > 2 | ||
| varargout{1} = fname; | ||
| end | ||
| if nargout > 3 | ||
| varargout{2} = fpath; | ||
| end | ||
| %identify device, if possible | ||
| if isfield(data{a},'Device_Num') | ||
| data{a}.Device_Num = unique(data{a}.Device_Num); | ||
| switch data{a}.Device_Num(1) | ||
| case 1 | ||
| data{a}.BirdName = 'Left_Hand'; | ||
| case 2 | ||
| data{a}.BirdName = 'Left_Arm'; | ||
| case 3 | ||
| data{a}.BirdName = 'Right_Hand'; | ||
| case 4 | ||
| data{a}.BirdName = 'Right_Arm'; | ||
| end %end switch | ||
| end %end if | ||
|
|
||
| end %end for loop | ||
|
|
||
| fclose(fid); | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bit should probably just be