Selecting a portion of the tables

조회 수: 9 (최근 30일)
BN
BN 2020년 1월 16일
댓글: Adam Danz 2020년 1월 16일
I have C.mat which includes 125 tables. I need to list only the first row of each 125 tables and put them under each other. I want only station_name, lat, and lon columns.
something like this:
station_name lat lon
Abadan 30.37 48.21
Abadeh 31.19 52.61
Abali 35.75 51.88
... ... ...
I was attached C.mat for you.

채택된 답변

Adam Danz
Adam Danz 2020년 1월 16일
% extract row 1 of each table stored in cell array C
firstRows = cellfun(@(m)m(1,:),C,'UniformOutput',false).';
% Vertically concatenate the first-rows into new table
T = vertcat(firstRows{:});
  댓글 수: 2
BN
BN 2020년 1월 16일
Thank you. I didn't know that. Then I simply use this to remove unwanted columns:
T = removevars(T,{'station_id','region_id', 'station_elevation', 'data', 'tmax_m', 'tmin_m', 'rrr24', 'tm_m'});
Adam Danz
Adam Danz 2020년 1월 16일
Or, if you know the column numbers and you know that all tables have the same column order, you could specify a vector of column numbers here
firstRows = cellfun(@(m)m(1,COLUMN_NUMBERS),C,'UniformOutput',false).';
% ^^^^^^^^^^^^^^

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by