Concatenate structure with subfields
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
John Chilleri
2017년 2월 22일
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
Jan
2017년 2월 23일
@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.
John Chilleri
2017년 2월 24일
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?
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!