Deleting rows that do not contain the state code i want.

조회 수: 6 (최근 30일)
Leulaye Maskal
Leulaye Maskal 2021년 11월 17일
댓글: Image Analyst 2021년 11월 18일
I have attached an excel with 3 columns aid, date, and mean. Each aid is code for a US state.
I want to cut out all rows that do not contain the following aid's
aid0045
aid0024
aid0046
aid0019
aid0038
aid0031
aid0041
aid0013
aid0042
aid0043
aid0030

채택된 답변

Leulaye Maskal
Leulaye Maskal 2021년 11월 18일
it worked thanks!! I assume I can use it to now pull out individual "aid's" like just 0045??
  댓글 수: 1
Image Analyst
Image Analyst 2021년 11월 18일
Yes you can. Just alter keeperStrings to be whatever you want. Since it worked, can you click the "Accept this Answer" on my Answer (not yours)? Thanks in advance.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 11월 17일
Try this:
% Read data into a table.
t = readtable('NPP_STATES_YRLY_MEAN.xls')
% Define "aid" strings that we want to keep/extract.
keeperStrings = {...
'aid0045'
'aid0024'
'aid0046'
'aid0019'
'aid0038'
'aid0031'
'aid0041'
'aid0013'
'aid0042'
'aid0043'
'aid0030'}
% Find out the rows where the keeper strings live.
rowsToKeep = ismember(t.aid, keeperStrings)
% Extract only those specific rows.
t2 = t(rowsToKeep, :)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by