Concatenate all arrays from a field in a structure

7 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Stephen23
Stephen23 il 13 Apr 2023
Modificato: Stephen23 il 13 Apr 2023

Più risposte (1)

Image Analyst
Image Analyst il 13 Apr 2023
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.

Categorie

Scopri di più su Structures in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by