MATLAB: Assign header line value to variable

.vfffgetlheader

I have a .vff file wich I open :
fid = fopen('test.vff');
The header is as follows:
ncaa;
rank=3;
type=raster;
format=slice;
bits=32;
bands=1;
size=256 256 256;
I want to extract size as a variable. So far I've tried:
size = fgetl(fid)
7 times in a row to get to the correct line, but the output I get is a char variable:
size =
'size=256 256 256;'
Instead of an array.
Thanks
CG

Best Answer

Once you have that string, convert it to a vector like this.
s = 'size=256 256 256;';
s(~isstrprop(s,'digit')) = ' ';
d = str2num(s)
% result
% d =
% 256 256 256
Option 2 (update after Stephen's good point below).
s = 'size=256 256 256;';
d = str2double(regexp(s,'\d+','match'))
Note that this will work even if the number of dimensions in 'size' changes (size = 256 256).
Related Question