I've seen a couple comments asking about the header line causing problems. From the documentation, you can use "HeaderLines" to tell it how many lines to skip. For instance: S = textscan(fid, '%s %f %f %f %f %f %d', 'HeaderLines', 1, 'Delimiter', ',')
Hello, thanks for your helpful video... I have approximately 2000 txt file and I want to upload them into matlab but I'm having difficulties with that .. how I can do this ?
Hi Heather Thank you so much for your videos, they have been so useful for learning to use MATLAB! I really like the way you explain things! I have a 4 GB text file that I need to analyse. Because of its size, I can't open it on MATLAB, EViews or Excel. I have been told to open it in 'parts', possibly using textscan. I have followed your steps and it just says S = {0 x 1} {0 x 2} etc, so it can't read any of my columns. I wondered if you know how to open a file in parts please? Thank you so much for your help! Emily
Hello Emily. I would recommend opening the file in MATLAB with fopen and then reading a line at a time with fgets or fgetl. line = fgetl(file_id) or line=fgets(file_id) If your analysis can be done reading a line at a time and looking for important info, this should work. If you want to use MATLAB to break the file up into smaller files, you could open it for reading and use another fopen command to open a new file for writing. Use a loop and every time you read in a line from the large input file, write it to a new file. Your loop can control how any times you repeat this and add your info to the smaller file. Hope this makes sense.
For this example I just deleted the first row by hand. But if you want the MATLAB code to read in the header, you could add a line like: headers=fgetl(fid) before the textscan line.
For this example I just deleted the first row by hand. But if you want the MATLAB code to read in the header, you could add a line like: headers=fgetl(fid) before the textscan line.
Thanks for video, Hi, Heather I have text file say data.1txt where look like have some text in few lines then step temperature volume 0 300 20 1 301 40 2 250 78 ... 100 582 60 then some text average number simulation end. Now I want only extract data from step 0 to 100 . How can I do that? Thanks,
Hello Ankit, If you are using textscan like the video does, your line of code to read in the data will be something like: S = textscan(fid, '%d %d %d') use percent sign and d 3 times with spaces in between S is a cell array with all 3 columns of data. You can look at the first column with S{1}. If you only want the first 3 numbers, use S{1}(1:3) This will be a vector containing the numbers 0, 1, 2. If you want 0-100 you could look at S{1}(1:101). And you can look at the other columns with S{2}(1:101). and S{3}(1:101)
Thanks for the good work. But I have a similar data and am doing basically the same thing but am not able to extract the column as you did in the video
Delete any header information and only leave the data in the file. Another thing you can check: If you open a file for reading and get a -1 as a return value, it means the open didn't work and you won't be able to use textscan or any other commands to read from the file.
hi thanks for the video it is really nice, i have a huge data which i am trying to import it in matlab using textscan actually it is an asc file, it works but the problem is that after each row i have zero till the end of the data. Can you please help me?