-
Notifications
You must be signed in to change notification settings - Fork 2
/
LoadFile.m
27 lines (21 loc) · 969 Bytes
/
LoadFile.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
% Function name....: LoadFile
% Date.............: January 06, 2002
% Author...........: Adriano de Oliveira Andrade
% Description......:
% LoadFile loads a text file. The data stored in the file are float numbers
% separated by spaces and with commas as a decimal symbol.
% Parameters.......:
% filename.........-> file name with extension
% Return...........:
% data.............-> vector containing the data loaded from the file.
function [data] = LoadFile(filename)
data = [];
fid = fopen(filename);%opening file
if(fid==-1),%Is fid a valid handle?
disp('Error: cannot open the file');
return;
end %if
[A,count] = fscanf(fid,'%c',inf);%reading file contents
str=strrep(A,',','.'); %changing commas by periods
data = sscanf(str,'%f')'; %converting string into float
fclose(fid);%closing file