MATLAB: How to import a spesific variable from a matrix in a file

fileimportmatrixreadspecifyvariable

I have a file "SANJOSE" that has two values in it "20 30"
I would like to use "loc1lat = importdata('SANJOSE')" command to import the first value of the 1×2 matrix, not the whole thing.
I am not sure what syntax to use after ('SANJOSE', ???) to specify which variable in the matrix I want.
Thanks

Best Answer

filename = 'SANJOSE';
(SANJOSE is a text file containing one line: 20 30)
Two options, either pass the file name SANJOSE as a string:
fid = fopen('SANJOSE','r'); %'r' means you only want to read the data.
your_value = fscanf(fid,'%d',1); %Will only read the first value
fclose(fid);
Or, pass the variable name (filename) that contains a string:
fid = fopen(filename,'r');
your_alternative_value = fscanf(fid,'%d',1);
fclose(fid);