Concatenate structure with subfields

I have a 1x1 structure which has 1x3 fields which further has 1x5 runs. Each run has different double data(same no. of columns, different no. rows). I want to concatenate it like run 1 its data 203x7 double, run 2 its data 216x7 double and so on. Also assign Column names to each 7 columns. How to do that within a loop?

1 Kommentar

Jan
Jan am 21 Feb. 2017
Can you post a small example? What does "1x5 runs" exactly mean?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

John Chilleri
John Chilleri am 22 Feb. 2017

0 Stimmen

Hello,
Hopefully I understand your question properly.
You can concatenate them with:
data = [datarun1; datarun2; ...; datarun5];
Furthermore, the easiest way to have column names is to have a separate variable (1x7) containing the names, unless you want to look into cells, in which you can have column names at the top before the data. There might exist a better way for column names, but these are some simple approaches.
Hope this helps!

2 Kommentare

Jan
Jan am 23 Feb. 2017
@M: Screenshots are cruel in the forum: We can see the data, but to use them all readers have to type a lot of boring code. Please post a small example of the input in valid Matlab syntax. Then it will be much easier to provide an answer and modify it until it matchs your needs.
Hello,
Perhaps you can make a new field in your struct with the concatenated data:
>> a.b.c = rand(4,3)
a =
b: [1x1 struct]
>> a.b.d = rand(5,3)
a =
b: [1x1 struct]
>> a.b.e = [a.b.c; a.b.d];
>> a.b.e
ans =
0.0462 0.3171 0.3816
0.0971 0.9502 0.7655
0.8235 0.0344 0.7952
0.6948 0.4387 0.1869
0.4898 0.2760 0.4984
0.4456 0.6797 0.9597
0.6463 0.6551 0.3404
0.7094 0.1626 0.5853
0.7547 0.1190 0.2238
(Concatenated a 4x3 with a 5x3 in new field a.b.e.). Is this closer to what you're needing?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Tags

Noch keine Tags eingegeben.

Gefragt:

M
M
am 21 Feb. 2017

Kommentiert:

am 24 Feb. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by