Extracting Data in Excel With Groups into Matlab

5 views (last 30 days)
Hello, I have a data in excel. Each row has a level from 1 to 10. Level shows subgroups. For example level 2 rows are subgroups of level 1 row. It goes like this. Is there a way that i can transfer it to matlab? It could be some cell in cell or a struct or is there anything else?
Also if there is a funtion that recognise levels, it could be very helpful
Example data:
Mass Level
23 1
10 2
2 3
8 2
13 2
10 3
3 3
  4 Comments
Dyuman Joshi
Dyuman Joshi on 8 Aug 2023
What is your data? Attach the excel file via the paperclip button.
How exactly do you want to group them?
Sevgi
Sevgi on 8 Aug 2023
I uploaded it to this comment. I want to tell Matlab that Level 3 parts are subgroups of Level 2 and Level 2 are subgroups of Level 1. I will use it later for calculating total mass of Level 2 using subparts of it which are Level 3.
For example in my example data in excel, 3rd rows mass should be 10 kg because Level 2 in 3rd row consist of row 4 and 5 which are Level 3. Because of that i need a fuction or a structure or anything else to upload Level relationships to Matlab.

Sign in to comment.

Answers (1)

Katy Weihrich
Katy Weihrich on 4 Aug 2023
Matlab has a option that automatically generates a code for reading excel files.
Go to Home --> Import Data (under Variable) --> open the excle file you want to load in --> select options that you need --> click on Inport Selection --> Generate Script
Matlap will open a untiteled scriped with a code that loads the data as you wish.
Tips for the selection of option:
  • You can select the format of the output under Output Type (in Improted data)
  • You can change the format of the variable (e.g. change Number to Categorical) below the variable name.
  • In Range deselect the first row with the variable names (e.g. A2:B8 instead of A1:B8)
  • if you read text files (e.g. .cvs) you need to ensure that the correct delimiter is selected and if you used excle in Germany you need to change the decimal seperator (under delimiter options) to comma instead of periode.
  1 Comment
Sevgi
Sevgi on 4 Aug 2023
What I try to do it getting these grouped values as grouped values. I will add a screenshot of how it looks in excel. I am trying to do it in the same way in matlab

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!