How to read excel data include specific word? cell?

1 回表示 (過去 30 日間)
Nicolas Alfred
Nicolas Alfred 2022 年 8 月 2 日
コメント済み: Star Strider 2022 年 8 月 2 日
Hi, all
[~,~,data] = xlsread('kpmarch.xlsx' );
data=[data(:,1) data(:,3) data(:,4) ];
There's 6columns in my excel file and I took A,C,D 3colomns form excel
next step, i only wanna take rows which include 'Planetary' in column C(OBSRVT_NM)
How can i do this..

採用された回答

Star Strider
Star Strider 2022 年 8 月 2 日
編集済み: Star Strider 2022 年 8 月 2 日
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1085430/kpmarch.xlsx')
T1 = 744×6 table
OBSR_YMD A_VALUE OBSRVT_NM K_VALUE CRT_DT OBSR_VYMD _______________________ _______ __________________ _______ ______________ __________________ {'2022-03-31 21:00:00'} {'27'} {'Planetary' } {'2'} {'2022-04-30'} {'20220331210000'} {'2022-03-31 21:00:00'} {'18'} {'Fredericksburg'} {'2'} {'2022-04-30'} {'20220331210000'} {'2022-03-31 21:00:00'} {'35'} {'College' } {'2'} {'2022-04-30'} {'20220331210000'} {'2022-03-31 18:00:00'} {'27'} {'Planetary' } {'4'} {'2022-04-30'} {'20220331180000'} {'2022-03-31 18:00:00'} {'18'} {'Fredericksburg'} {'3'} {'2022-04-30'} {'20220331180000'} {'2022-03-31 18:00:00'} {'35'} {'College' } {'4'} {'2022-04-30'} {'20220331180000'} {'2022-03-31 15:00:00'} {'27'} {'Planetary' } {'4'} {'2022-04-30'} {'20220331150000'} {'2022-03-31 15:00:00'} {'18'} {'Fredericksburg'} {'4'} {'2022-04-30'} {'20220331150000'} {'2022-03-31 15:00:00'} {'35'} {'College' } {'4'} {'2022-04-30'} {'20220331150000'} {'2022-03-31 12:00:00'} {'27'} {'Planetary' } {'4'} {'2022-04-30'} {'20220331120000'} {'2022-03-31 12:00:00'} {'18'} {'Fredericksburg'} {'3'} {'2022-04-30'} {'20220331120000'} {'2022-03-31 12:00:00'} {'35'} {'College' } {'6'} {'2022-04-30'} {'20220331120000'} {'2022-03-31 09:00:00'} {'27'} {'Planetary' } {'4'} {'2022-04-30'} {'20220331090000'} {'2022-03-31 09:00:00'} {'18'} {'Fredericksburg'} {'3'} {'2022-04-30'} {'20220331090000'} {'2022-03-31 09:00:00'} {'35'} {'College' } {'5'} {'2022-04-30'} {'20220331090000'} {'2022-03-31 06:00:00'} {'27'} {'Planetary' } {'5'} {'2022-04-30'} {'20220331060000'}
Lv = ismember(T1{:,3},'Planetary');
Result = T1(Lv,[1 3 4])
Result = 248×3 table
OBSR_YMD OBSRVT_NM K_VALUE _______________________ _____________ _______ {'2022-03-31 21:00:00'} {'Planetary'} {'2'} {'2022-03-31 18:00:00'} {'Planetary'} {'4'} {'2022-03-31 15:00:00'} {'Planetary'} {'4'} {'2022-03-31 12:00:00'} {'Planetary'} {'4'} {'2022-03-31 09:00:00'} {'Planetary'} {'4'} {'2022-03-31 06:00:00'} {'Planetary'} {'5'} {'2022-03-31 03:00:00'} {'Planetary'} {'5'} {'2022-03-31 00:00:00'} {'Planetary'} {'4'} {'2022-03-30 21:00:00'} {'Planetary'} {'2'} {'2022-03-30 18:00:00'} {'Planetary'} {'2'} {'2022-03-30 15:00:00'} {'Planetary'} {'1'} {'2022-03-30 12:00:00'} {'Planetary'} {'2'} {'2022-03-30 09:00:00'} {'Planetary'} {'1'} {'2022-03-30 06:00:00'} {'Planetary'} {'1'} {'2022-03-30 03:00:00'} {'Planetary'} {'1'} {'2022-03-30 00:00:00'} {'Planetary'} {'2'}
There are likely also other approaches.
.
  2 件のコメント
Nicolas Alfred
Nicolas Alfred 2022 年 8 月 2 日
Thank you very much, i can go to the next step :)
Star Strider
Star Strider 2022 年 8 月 2 日
As always, my pleasure!

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 8 月 2 日
It is not possible to read rows selectively, other than by consecutive position.
You will need to do something such as
mask = ismember(data(:,3), 'Planetary');
subset = data(mask, [1 4]);
Note: we recommend that you switch to readtable()
data = readtable('kpmarch.xlsx');
mask = ismember(data.OBSRVT_NM, 'Planetary');
subset = data(mask, [1 4]);
Then subset{:,2} would be datetime objects.
Your xlsx file is odd: all of your numbers are represented as text.
  1 件のコメント
Nicolas Alfred
Nicolas Alfred 2022 年 8 月 2 日
Thank you, I didn't know that rows can't be read selectively, I searched it for hours ..

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

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by