How to replace and interchange values?

2 views (last 30 days)
x= [15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 0];
a = unique(x);
%Last column of x replaced by "a" i.e [ -45 -30 0 15 30 45 60 90]
y= [15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 -45;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 -30;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 0;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 15;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 30;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 45;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 60;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 90;];
value = [15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 -45;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 -30;
%row of initial guess "x" should be deleted.
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 15;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 30;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 45;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 60;
15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 90;];

Accepted Answer

the cyclist
the cyclist on 27 Feb 2016
Edited: the cyclist on 27 Feb 2016
If I understand your question correctly, here is one way:
x= [15 30 45 60 -45 -30 0 90 15 30 45 60 -45 -30 0 90 15 45 60 -45 -30 0];
a = unique(x);
y = repmat(x,numel(a),1);
y(:,end) = a';
value = y;
rowToRemove = find(x(end)==a);
value(rowToRemove,:) = [];
  2 Comments
Triveni
Triveni on 27 Feb 2016
Thanks....and please tell me to delete x from this too. i have to delete row matching with x? your program calculating "y". and i need value.
the cyclist
the cyclist on 27 Feb 2016
I edited my answer to give you y and value as you stated.

Sign in to comment.

More Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!