Extract data from a structure

I have a "1x1 struct" with 2 fields. One of the fields is data and is a 7909x10 double, while the other field is textdata that is a 1x1 cell containing the header of the output file.
I do not know how to make it so that I only have the data field that is a 7909x10 double. From there I only need columns 1,2,3 and 6 from those 10 columns and would like to delete the other 6 columns to make a new data structure.

回答 (2 件)

Birdman
Birdman 2018 年 3 月 26 日

4 投票

One approach:
A.a=A.a(:,[1 2 3 6])
where A is struct and a is its field.

4 件のコメント

jfrazie9
jfrazie9 2018 年 3 月 26 日
Thanks!
jfrazie9
jfrazie9 2018 年 3 月 26 日
With this new data structure can I filter by the rows I want as well? The 7909 rows are various time for 55 flow paths, thus each flow path accounts for roughly 142 of the 7909 values.
Can I filter it so that the values in column 1 are only flow paths 16-20 for example?
Birdman
Birdman 2018 年 3 月 26 日
Yes, for instance:
A.a(16:20,1)
will extract the values in column 1 from row 16 to row 20.
jfrazie9
jfrazie9 2018 年 3 月 26 日
My mistake I was unclear, the first column is the pathID numbered 1-55, where there are approximately 142 rows with pathID = 1, another 142 with pathID = 2. How do I sort based on the value in the first column would be a better question?

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

Ameer Hamza
Ameer Hamza 2018 年 4 月 21 日

1 投票

From your questions and comments, the following solution will work for you. Suppose you original struct is A and you want to create another struct object B by deleting some columns of A and sorting rows according to column 1.

B = A;
B.data = B.data(:, [1 2 3 6]); % delete columns of data
[~, ind] = sort(B.data(:,1)); % get sorted indexes for column 1
B.data = B.data(ind, :); % now sort all rows of data matrix.

This will give you required struct B.

カテゴリ

ヘルプ センター および File ExchangeStructures についてさらに検索

質問済み:

2018 年 3 月 26 日

回答済み:

2018 年 4 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by