MATLAB: How to load an array without delimiter from file -


i have been using load function until load space separated files arrays in matlab. wastes lots of space me since values either 0 or 1. instead of writing files

0 1 1 0  1 1 1 0 

i removed spaces create half big files like:

0110 1110 

however load doesn't work correctly more (creates matrix think first number, 2x1 instead of 2x4). looked around importdata, reading file line line , lots of other stuff couldn't find clear solution. want read matrix file doesn't have delimiter. every number element of array

does know of clean way this? thanks

here 1 way:

data.txt

0110 1110 

matlab

%# read file lines cell array of strings fid = fopen('data.txt','rt'); c = textscan(fid, '%s', 'delimiter',''); fclose(fid);  %# extract digits c = cell2mat(cellfun(@(s)s-'0', c{1}, 'uniform',false)); 

result:

c =      0     1     1     0      1     1     1     0 

if concerned memory, maybe cast boolean: c = logical(c) 0/1 possible values.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -