extract 1 row data of 1 table

조회 수: 1 (최근 30일)
hang dong
hang dong 2019년 5월 24일
편집: Jatin 2024년 8월 23일
I want to extract the data of a row in a table, how to do it
exam: Name address age
hang VN 18
nam vn 40
lan vn 23
I want to retrieve the information of a man named Nam
help me!
  댓글 수: 3
Ramesh Bala
Ramesh Bala 2019년 5월 24일
exam1(1,1:length(exam))=exam; -for 1st row and do the same for rest
hang dong
hang dong 2019년 5월 24일
1.PNG
I want to find an element in the table
exam: from pos = 11 i can find iwant = 542013

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

답변 (1개)

Jatin
Jatin 2024년 8월 23일
편집: Jatin 2024년 8월 23일
Hi hang dong,
There are few ways how this can be achieved.
1. If you don’t have fixed value to search on every time, you can use logical vectors to extract the row with value equal to the key and you can get the required output using the syntax given below for your example table:
% Extract the age of the person named 'nam'
% Use the equality operator to compare strings directly
Age = dataTable.Age(strcmp(dataTable.Name, 'nam'));
2. If the “Name” column is used every time for accessing table values, you can set the “RowNamesproperty of the table to the “Name” column and then you can access the table values using a syntax as below:
% Set the 'Names' as row names using the object property
dataTable.Properties.RowNames = Names;
% Extract the age of the person named 'nam'
Age = dataTable{'nam', 'Age'};
Kindly go through this documentation for more on accessing values from table:
Hope this helps!

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by