Please How do I extract data from a struct

121 ビュー (過去 30 日間)
osemudiamen oriabure
osemudiamen oriabure 2022 年 5 月 6 日
回答済み: Bhavana Ravirala 2022 年 5 月 9 日
Please Im trying to merg data from a variable (struct) to another table. How do I archieve this?
  2 件のコメント
Monica Roberts
Monica Roberts 2022 年 5 月 6 日
What does the struct look like? What variable in the struct are you trying to get?
You can use dot indexing to get variables within a struct https://www.mathworks.com/help/matlab/ref/struct.html
% If struct "s" has fields "a", "b", "c"
myVariable = s.b; % collects the values in "b"
Star Strider
Star Strider 2022 年 5 月 6 日
The struct2table function will convert the structure to a table.
Integrating it with another table depends on what the variables are and the existing table. Merging them could be anything from straightforward to impossible.

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

回答 (1 件)

Bhavana Ravirala
Bhavana Ravirala 2022 年 5 月 9 日
Hi osemudiamen oriabure,
I understand that you are trying to convert a struct variable to a table and then merge it with another table. You may convert a struct into a table with the help of the "struct2table" function and join with another table with the help of "join" function.
Example:
s.person=[ 'a' ,'b', 'c'];
s.height=[ 5.3, 5.11, 6.1];
t= struct2table(s); % converting struct to table
T= join(T,t); % T is already existing table
For more information refer below documentations:
Hope this helps!!

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by