How to unstructure the structure data?

4 ビュー (過去 30 日間)
Ammy
Ammy 2021 年 9 月 18 日
編集済み: Image Analyst 2021 年 9 月 18 日
I want to find the mean of all rows in the data set .
But the data in the workspace is in the following formate.
let A be data set.
A=<54×10 struct>
where each row of A is in the following format
<1x1 struct> <1x1 struct> <1x1 struct> <1x1 struct> <1x1 struct> <1x1 struct> <1x1 struct> <1x1 struct> <1x1 struct> <1x1 struct>
How can I find the mean of each row of A.
  3 件のコメント
Stephen23
Stephen23 2021 年 9 月 18 日
Rik
Rik 2021 年 9 月 18 日
Your data is a struct array. Does it have only 1 field?

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

採用された回答

Rik
Rik 2021 年 9 月 18 日
If you use the normal dot indexing with a struct array, that will generate a comma separated list.
You can put that between brackets to concatenate the resulting values, but you will need to use reshape to restore the original shape:
fn=websave('DATA.mat','https://www.mathworks.com/matlabcentral/answers/uploaded_files/742259/DATA.mat');
S=load(fn);npcr=S.npcr
npcr = 54×10 struct array with fields:
npcr_score
reshape([npcr.npcr_score],size(npcr))
ans = 54×10
0.9959 0.9965 0.9963 0.9966 0.9959 0.9964 0.9963 0.9963 0.9958 0.9963 0.9960 0.9962 0.9962 0.9960 0.9966 0.9960 0.9962 0.9960 0.9962 0.9962 0.9959 0.9965 0.9963 0.9966 0.9959 0.9964 0.9963 0.9963 0.9958 0.9963 0.9960 0.9965 0.9960 0.9959 0.9966 0.9957 0.9960 0.9963 0.9960 0.9965 0.9961 0.9964 0.9961 0.9960 0.9962 0.9958 0.9961 0.9960 0.9963 0.9962 0.9961 0.9964 0.9961 0.9960 0.9962 0.9958 0.9961 0.9960 0.9963 0.9962 0.9959 0.9959 0.9958 0.9962 0.9960 0.9962 0.9958 0.9960 0.9958 0.9956 0.9960 0.9962 0.9962 0.9960 0.9966 0.9960 0.9962 0.9960 0.9962 0.9962 0.9959 0.9965 0.9963 0.9966 0.9959 0.9964 0.9963 0.9963 0.9958 0.9963 0.9960 0.9962 0.9961 0.9960 0.9963 0.9963 0.9961 0.9961 0.9962 0.9962
  6 件のコメント
Ammy
Ammy 2021 年 9 月 18 日
Sorry ,
Sure
thanks
Image Analyst
Image Analyst 2021 年 9 月 18 日
編集済み: Image Analyst 2021 年 9 月 18 日
@Rik, this happens so often that's why I (when I remember) to attach their data to my answer so that in case they delete it (which for some reasons they often do), it's still there. Perhaps you still have it, if you downloaded it, and can attach it. I always download rather than read it directly off the Mathworks server because (as we've found out here), if the user deletes it, it's no longer on the Mathworks server.
Also if it's the user's first or second post (not the case here), I also copy the question and attach it as a text file "OriginalQuestion.txt" to my Answer. And if it's their first or second question and they have flags that said they deleted their question, I just won't answer, and sometime tell them why I won't answer.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by