Concatenate all arrays from a field in a structure

7 ビュー (過去 30 日間)
AnirudhNA
AnirudhNA 2023 年 4 月 13 日
編集済み: Stephen23 2023 年 4 月 13 日
I have a structure with a size 1 x 10845 and 4 fields. Each of the 10845 values consists of arrays with various lengths.
The struct is named S and it looks like this:
I want to extract all these values and concatenate them into a new array. So essentially, I want 4 different arrays for the four fields, consisting of all the values in the struct, put together as a long array.
I've tried to implement the code with the following for loop, but I get the error
for 1 = 0:length(S.A)
A_combined = S.A(i);
end
"Error using length
Too many input arguments."
I've also tried using arrayfun(@(x) copy(x.A), S);
but I get the following error:
"Undefined function 'copy' for input arguments of type 'double'."
I've been struggling with this problem for a few days now and I can't find the solution. Do I have the wrong approach or am I missing something?

採用された回答

Stephen23
Stephen23 2023 年 4 月 13 日
編集済み: Stephen23 2023 年 4 月 13 日

その他の回答 (1 件)

Image Analyst
Image Analyst 2023 年 4 月 13 日
Did you try
allA = [S.A]
? Or try vertcat or horzcat
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
We can't test our code with an image of your variable, we need the actual variable.

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by