Multipul textscan into one matrix

Hey,
I'm new to Matlab and have no experience in textscan functions..
I have 3 folders, each of them containing 4 text files with a data that have the same format in all :
"Filed_Size(square_meter) Total_Product(ton) Grade_A_Product(ton) Grade_B_Product(ton) Grade_C_Product(ton) Sweetnes(1-100) Shelf_Life(days)"
, but with different numbers in every category.
I got an assignment, to read all the data from these 3 folders(12 text files= 3 folders*4 text files in each) into one matrix. I tried to loop with "fopen" for each folder seperatly but than I get a folder ID of (-1).
this is what I have for now-
file_id_lot247_2017 = fopen('2017_lot_no_247_Data.txt');
file_id_lot247_2016= fopen('2016_lot_no_247_Data.txt');
file_id_lot247_2015= fopen('2015_lot_no_247_Data.txt');
file_id_lot247_2014= fopen('2014_lot_no_247_Data.txt');
As you can see, I have a folder name 247 and I need to read all the text files from it..but I have tow more folders to read and I need ALL the 12 text scan to be in one matrix.
the text in each look like this- **the numbers changes in each text**
Filed_Size(square_meter) Total_Product(ton) Grade_A_Product(ton) Grade_B_Product(ton) Grade_C_Product(ton) Sweetnes(1-100) Shelf_Life(days)
406 12 5 6 1 65 12
Can someone help me please?
Thank you!

댓글 수: 1

dpb
dpb 2019년 12월 28일
See IA's demo to traverse subdirectories at link <Read-all-files-inside-more-than-one-directory>. Use dir() with wildcard to return all of a given lot number (if more than one there, altho perhaps what you're meaning is there are a bunch of different lot numbers?)
Need to know a little more about the storage organization and naming and whether there are other files besides to be able to be precise, but that's general idea. Don't create file handles with the metadata in the name; just use a single fid and handle each file in a loop one at a time, keeping track of which year and lot is which by variables or other storage organization depending upon just what it is that is being done.

답변 (0개)

이 질문은 마감되었습니다.

질문:

2019년 12월 28일

마감:

2021년 8월 20일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by