How to extract specific data from data files?

조회 수: 14 (최근 30일)
lina
lina 2022년 6월 10일
답변: Kevin Holly 2022년 6월 10일
I want to extract specific data from a table that I've transferred into Matlab. The table looks kind of like this.
id. dataa datab datac datad
--------- ----------- -------- ----------- --------
111 135 134 ... ...
111 143 176 ...
111 124 187
222 123 287
222 473 853
I specifically want to extract all the data for a specific id number.
I am also using an input statement to get the ID number for which I'm supposed to extract data.
So far I have something similar to
giveid = input('insert the ID for analysis: ');
Thank you for any help.

답변 (1개)

Kevin Holly
Kevin Holly 2022년 6월 10일
data = [111 135 134
111 143 176
111 124 187
222 123 287
222 473 853]
data = 5×3
111 135 134 111 143 176 111 124 187 222 123 287 222 473 853
t = array2table(data)
t = 5×3 table
data1 data2 data3 _____ _____ _____ 111 135 134 111 143 176 111 124 187 222 123 287 222 473 853
t.Properties.VariableNames = ["ID" "DataA" "DataB"]
t = 5×3 table
ID DataA DataB ___ _____ _____ 111 135 134 111 143 176 111 124 187 222 123 287 222 473 853
% giveid = input('insert the ID for analysis: ');
giveid = 111 %You can use the line above instead
giveid = 111
t(t.ID==giveid,:)
ans = 3×3 table
ID DataA DataB ___ _____ _____ 111 135 134 111 143 176 111 124 187

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by