MATLAB: Read fixed number of numbers from text file MATLABmatrix i have this matrix bellow save in a text file called test.txt 1 2 3 …… ……100 101 102 …… ..200 ……………………… 901 902 …….1000 i want to read only the first 500 numbers from it . how to do it ? thanks in advance Best Answer I assume the dots are meant as ellipses and not literally dots in the file. If so, you can use textscan pretty effectively here.fid = fopen(filename);d = textscan(fid,'%f',500);d = d{1};fclose(fid);And if there are literally dots, d = textscan(fid,'%f',500,'Whitespace',' .'); Related SolutionsMATLAB: How to read a matrix contain ‘?’ fid = fopen('filename.txt')d = textscan(fid,'%f%f%f', 'Delimiter', ';', 'TreatAsEmpty', '?', 'EmptyValue', 0, 'CollectOutput', 1)fclose(fid)out = d{1}; MATLAB: Cannot Read data from text file FileID = fopen('data.txt','r');C = textscan(FileID,'%s %f %f','HeaderLines',1,'Delimiter',',');fclose(FileID);C{1}C{2}C{3} Related QuestionTo read a text file using matlabI want to delete all the headerlines and delimiters from the data in the below attached text fileI aam having error when i am trying to load csv file and i am having error like this which i mentioned so please help me someone
Best Answer