Urgent: I dont have a clue how to merge to Matrices and split-up Arrays.

a) Given 2 data Matrices
Data A=[1 120 DataB= 1 90 1 130 2 92 2 140 3 93 3 180 3 160]
I need to merge the two Data sets so that the result looks like TargetData= 1 120 91 1 130 91 2 140 92 3 180 92 3 160 93
b) Array=[2,8,3,30,4,50,100,200,4,80,500]. It is required to split it up into three arrays with different ranges: [0-10],[10-100] and [100-1000]
HOW TO DO THIS??

2 Comments

Sorry, corrections in part a.
DataA= 1 120
1 130
2 140
3 180
3 160
DataB= 1 91
2 92
3 93
Target Data= 1 120 91
1 130 91
2 140 92
3 180 92
3 160 93
http://www.mathworks.com/matlabcentral/answers/29922-why-your-question-is-not-urgent-or-an-emergency

Sign in to comment.

Answers (1)

For part (a), you can do the following:
DataA= [1 120
1 130
2 140
3 180
3 160];
DataB= [1 91
2 92
3 93];
cidx = bsxfun(@eq,DataA(:,1),DataB(:,1)');
for m = 1:size(cidx,2)
DataA(cidx(:,m),3) = DataB(m,2);
end
I didn't quite get part (b), could you elaborate more, just as you have done in part (a), what is the desired output?

Asked:

on 4 Mar 2012

Community Treasure Hunt

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

Start Hunting!