Uploading an excel sheet that contains some texts

3 ビュー (過去 30 日間)
Yaser Khojah
Yaser Khojah 2021 年 2 月 7 日
コメント済み: Walter Roberson 2021 年 2 月 10 日
Dear there, I need a help with uploading an Excel sheet then converting everything to a matrix. My issue comes as there are some texts in the first column and each one contains space. So, when I uploaded the excel sheet, I struggled to call a text as a variable (e.g. Field_A) and its belonging numbers (e.g all the rows). For example, my table would look like the below. Please note my sheet is much more complex than the below. I need an easy way to do the following please.
% my excel sheet would look like this one. This is only an example, while mine is more compicated
Jan Feb Mar
Field A 10 90 80
Field B 20 10 70
Field C 50 10 30
Total Production 80 110 180
% after i uploaded the excel sheet, I want to create my variable as below
Field_A = [10, 90, 80]
Field_B = [20, 10, 70];
...
Total_Prouduction = [80, 110, 180]

採用された回答

Walter Roberson
Walter Roberson 2021 年 2 月 7 日
t = readtable(filename) ;
field_yeilds = t{1:end-1, 2:end};
total_prod = t{end, 2:end};
crosscheck = sum(field_yeilds,1) - total_prod %(should be 0)
  5 件のコメント
Yaser Khojah
Yaser Khojah 2021 年 2 月 10 日
Dear@Walter Roberson thank you so much for your help. I agree with you but wanted a way as I have many excel sheet to deal with. Dear @Siddharth Bhutiya thank you so much for sharing this. I will try it on my code and ask some questions. I'm sorry for my late response as I have the matlab installed in a different machine which I cant access all the time.
Walter Roberson
Walter Roberson 2021 年 2 月 10 日
The more excel sheets you have to deal with, the more likely you are to accidentally clobber some variable you were using for something else.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by