How to Merge two structures.

I'm trying to merge two structures together and can't figure out how to do it. I have one with data [x, x, 0, 0, x, x] and one with data [0, 0, y, y, 0 0] and I would like [x, x, y, y, x, x]. I have tried using union and that just joins the two front to back, I was told to try using "&" but that also didn't work. Any ideas would be great. I don't mind using the help feature in matlab, just not sure what to search for or what functions to use.
Thank you,
Nick

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 23일

0 개 추천

x=10;
y=20;
data1=[x, x, 0, 0, x, x]
data2= [0, 0, y, y, 0 0]
data=data1;
data(data1==0)=data2(data2~=0)

추가 답변 (2개)

Nick
Nick 2013년 5월 23일

1 개 추천

Thank you for the help. I also found that I could just do "x = y + z" and it gave me the same results and in my situation that works fine.
Sean de Wolski
Sean de Wolski 2013년 5월 23일

0 개 추천

So:
x.data = [1 1 0 0 1];
y.data = [pi pi pi pi pi];
z.data = x.data;
idx = ~z.data;
z.data(idx) = y.data(idx);

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

질문:

2013년 5월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by