Concatenate structure with subfields

조회 수: 1 (최근 30일)
M
M 2017년 2월 21일
댓글: John Chilleri 2017년 2월 24일
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
Jan
Jan 2017년 2월 21일
Can you post a small example? What does "1x5 runs" exactly mean?

댓글을 달려면 로그인하십시오.

답변 (1개)

John Chilleri
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
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
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by