How to extract data from data file? (2024)

19 views (last 30 days)

Show older comments

Sunil Oulkar on 18 Jan 2017

  • Link

    Direct link to this question

    https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file

  • Link

    Direct link to this question

    https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file

Answered: Nnamdi Onwuegbuchu on 9 Jun 2022

Accepted Answer: Guillaume

I have an .xls file which consists of 1st column is dates and time and other n rows and n columns data.... in this file, I want to extract data from between 8/9/2015 21:00 to 8/10/2015 9:00 then next 8/10/2015 21:00 to 8/11/2015 9:00 like wise for same all interval in one output file.

Input: 8/9/2015 9:00 1392 14.51 11.57 11.37 8/9/2015 10:30 1395 13.97 15.4 14 8/9/2015 12:00 1398 13.93 17.11 16.4 8/9/2015 13:30 1401 13.87 18.64 17.44 8/9/2015 15:00 1404 13.86 19.66 17.73 8/9/2015 16:30 1407 13.88 19.23 16.19 8/9/2015 18:00 1410 13.61 16.55 14.56 8/9/2015 19:30 1413 12.92 13.51 12.38 8/9/2015 21:00 1416 12.58 10.91 10.95 8/9/2015 22:30 1419 12.54 10.24 10.53 8/10/2015 0:00 1422 12.51 9.74 10.13 8/10/2015 1:30 1425 12.49 9.52 9.98 8/10/2015 3:00 1428 12.47 10.28 10.13 8/10/2015 4:30 1431 12.46 9.4 8.96 8/10/2015 6:00 1434 12.46 9.02 8.97 8/10/2015 7:30 1437 13.22 9.45 9.59 8/10/2015 9:00 1440 14.52 11.44 10.5 8/10/2015 10:30 1443 14.03 13.71 11.88 8/10/2015 12:00 1446 13.99 14.58 12.76 8/10/2015 13:30 1451 13.97 16 14.13 8/10/2015 15:00 1452 13.96 15.99 13.57 8/10/2015 16:30 1455 14.01 14.77 12.96 8/10/2015 18:00 1458 13.96 14.56 12.3 8/10/2015 19:30 1461 12.98 11.28 10.47 8/10/2015 21:00 1464 12.6 9.17 9.45 8/10/2015 22:30 1467 12.55 7.962 8.86 8/11/2015 0:00 1470 12.52 7.958 8.65

Output: 8/9/2015 21:00 1416 12.58 10.91 10.95 8/9/2015 22:30 1419 12.54 10.24 10.53 8/10/2015 0:00 1422 12.51 9.74 10.13 8/10/2015 1:30 1425 12.49 9.52 9.98 8/10/2015 3:00 1428 12.47 10.28 10.13 8/10/2015 4:30 1431 12.46 9.4 8.96 8/10/2015 6:00 1434 12.46 9.02 8.97 8/10/2015 7:30 1437 13.22 9.45 9.59 8/10/2015 9:00 1440 14.52 11.44 10.5 8/10/2015 21:00 1464 12.6 9.17 9.45 8/10/2015 22:30 1467 12.55 7.962 8.86 8/11/2015 0:00 1470 12.52 7.958 8.65 .......... ... ... ... ...

and so on ....

3 Comments

Show 1 older commentHide 1 older comment

Preethi on 18 Jan 2017

Direct link to this comment

https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file#comment_421176

  • Link

    Direct link to this comment

    https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file#comment_421176

hi,

you can use xlsread() function.

Sunil Oulkar on 18 Jan 2017

https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file#comment_421182

  • Link

    Direct link to this comment

    https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file#comment_421182

I have hourly data from that .xls file I want to extract data between 6 am to 6 pm for each day in one file.

Shubhangi Saini on 19 Feb 2019

Direct link to this comment

https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file#comment_672796

  • Link

    Direct link to this comment

    https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file#comment_672796

If it is a csv file then you can use

Pin_data = csvread('spect - Sheet1.csv');

col1 = Pin_data(:, 1); // to extract the data of 1st column

col2 = Pin_data(:, 2); // to extract the data of 2nd column

I hope this may help .

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Guillaume on 18 Jan 2017

  • Link

    Direct link to this answer

    https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file#answer_250993

  • Link

    Direct link to this answer

    https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file#answer_250993

Open in MATLAB Online

Rather than the outdated and less powerful xlsread you can use readtable to load your excel file into a table. You can then convert that table into a timetable with table2timetable which will make manipulating rows of data based on time much easier. You can then use timerange or standard comparison and logical operators to filter the rows of the timetable.

It's going to be something like:

t = readtable('yourxlsfile.xlsx'); %may need some extra options

t = table2timetable(t);

dates = t.Date; %variable name 'Date' will be something else

tokeep = hour(dates) >= 6 & hour(dates) <= 18;

filteredt = t(tokeep, :); %only keep rows whose hour is between 6am and 6pm

3 Comments

Show 1 older commentHide 1 older comment

Sunil Oulkar on 18 Jan 2017

Direct link to this comment

https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file#comment_421199

  • Link

    Direct link to this comment

    https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file#comment_421199

  • input.xls
  • output.xls

I am using Matlab 2013b. I am getting error. For the reference please see the below attached input and output file.

Guillaume on 18 Jan 2017

Direct link to this comment

https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file#comment_421203

  • Link

    Direct link to this comment

    https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file#comment_421203

Open in MATLAB Online

That is a version that predates the very useful datetime type (came with 2014b) that makes date manipulation so much easier, the table type that makes reading excel files so much easier and the timetable type that makes manipulating tables based on time so much easier.

My advice: upgrade to a newer version.

A possible way to make it work in R2013b:

[~, ~, xlcontent] = xlsread('yourxlsfile.xlsx');

dates = datevec(xlcontent(:, datecolumn), 'dd/mm/yyyy HH:MM') %or whichever date format you use

tokeep = dates(:, 4) >= 6 & dates(:, 4) <= 18;

filteredcontent = xlcontent(tokeep, :);

Sunil Oulkar on 18 Jan 2017

Direct link to this comment

https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file#comment_421303

  • Link

    Direct link to this comment

    https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file#comment_421303

Thank you!

Sign in to comment.

More Answers (1)

Nnamdi Onwuegbuchu on 9 Jun 2022

  • Link

    Direct link to this answer

    https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file#answer_982445

  • Link

    Direct link to this answer

    https://jmaab.mathworks.com/matlabcentral/answers/320853-how-to-extract-data-from-data-file#answer_982445

Hi roomies, pls how can i extract imported data on matlab before sending it to model trainer

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABLanguage FundamentalsData TypesTables

Find more on Tables in Help Center and File Exchange

Tags

  • extract

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


How to extract data from data file? (10)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

Contact your local office

How to extract data from data file? (2024)

FAQs

How to extract data from a file in Matlab? ›

Usually, the easiest way to import text data into MATLAB is to use the extractFileText function. This function extracts the text data from text, PDF, HTML, and Microsoft Word files. To import text from CSV and Microsoft Excel files, use readtable . To extract text from HTML code, use extractHTMLText .

How do I take data from a file? ›

The basic steps in reading data from a file are:
  1. Tell the program where to find the data.
  2. Open a path to the data.
  3. Set up the program variables to access the data.
  4. Read the data.
  5. Close the data path.

Which tool is used to extract data? ›

Data extraction examples and use cases

An ETL tool can extract data from these various sources and load it into a data warehouse where it can be analyzed and mined for insights into brand perception.

How can information be extracted from data? ›

How does Data Extraction work?
  1. Identifying Data Sources.
  2. Source Connection.
  3. Query or Retrieval.
  4. Data Transformation and Loading.
  5. Web Scraping.
  6. API-Based Extraction.
  7. Text Extraction (Natural Language Processing – NLP)
  8. OCR.
Jan 5, 2024

How do you extract data in Excel? ›

Select the cells or range of data you want to extract. Copy the selected data (Ctrl + C on Windows, Command + C on Mac). Paste the data into your desired application (e.g., another Excel file, Word document, or text editor) using Ctrl + V (Windows) or Command + V (Mac).

How do I extract specific data from a table? ›

As we've already mentioned, manual extraction is the simplest extraction method. To use it, you need to open your dataset and select the data you want to extract. Then, copy the selected data and paste it into a new spreadsheet or another app where you need to work with that information.

What is a data extraction tool? ›

Data extraction tools integrate with business intelligence (BI) systems, enabling businesses to consolidate data from multiple sources into a central repository. Businesses can then analyze and transform this data into meaningful insights to formulate effective business strategies.

References

Top Articles
Latest Posts
Article information

Author: Rev. Porsche Oberbrunner

Last Updated:

Views: 6270

Rating: 4.2 / 5 (73 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Rev. Porsche Oberbrunner

Birthday: 1994-06-25

Address: Suite 153 582 Lubowitz Walks, Port Alfredoborough, IN 72879-2838

Phone: +128413562823324

Job: IT Strategist

Hobby: Video gaming, Basketball, Web surfing, Book restoration, Jogging, Shooting, Fishing

Introduction: My name is Rev. Porsche Oberbrunner, I am a zany, graceful, talented, witty, determined, shiny, enchanting person who loves writing and wants to share my knowledge and understanding with you.