fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 28, 2016 14:34:07 GMT
This thread is reserved for tips & tricks all around MatLab.
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on Jun 1, 2016 18:58:10 GMT
If you want to import external data into Matlab then best way is to use readtable function.
% file name mlFileName = 'C:\\MyData.csv';
%% Reading and importing the external data file and converting to table format % readtable function requires minimum Matlab 2013b % imports to table format tab = readtable (mlFileName, 'Delimiter', '\t', 'ReadVariableNames', true);
Upper readtable arguments assume the file's data being separated by tab and having header.
Readtable() function imports to table format. In order to get array format you have to use function table2array(..).
%% Converting table format to array arr = table2array(tab); % table is a x-y matrix now stored to arr
Now if your data is data being exported from AmiBroker and your data contains AB's Null (which is equal to -1e+10) Then in order to make AB's Null getting converted to MatLab's NaN (not a number) you do the following:
%% Converting unwanted data to NaN % Converting AmiBroker's Null (-1e+10) from within imported % AmiBroker matrix to MatLab's NaN ('not a number') format abnull = arr == -1e+10; % returns true/false if there is/isn't Null within arr arr(abnull) = NaN; % line says: if there is Null within arr then replace by NaN
Now 'arr' variable is a proper matrix you can do some calculation with. I.e.
med = nanmedian(arr); % median function excluding NaN from calculation
Or you may do some plotting of arr.
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on Jun 1, 2016 19:09:51 GMT
If you want Matlab to store and to immediately output the result in Command Window then you don't add semicolon at the end of the line. Otherwise if you just want to store a variable for later result view then, oh well, you add semicolon.
|
|