# Help sorting a matrix into other matrix

조회 수: 1(최근 30일)
Conner Carriere 2021년 2월 9일
답변: darova 2021년 2월 11일
I have one matrix that we will call the postitions matrix
positions = (1 2 3, 4 5 6, 7 8 9);
Then we have the matrix that needs to be sorted into the positions matrix
XYColor =
1 3 1 1 1
1 2 1 0 1
1 1 0 1 0
2 1 0 0 1
2 2 1 1 1
2 3 1 0 0
3 1 1 0 0
3 2 1 0 0
3 3 1 1 0
%x y rgb triplet associated with the x and y
What I need to do is take the x and y and put it a certain place in the position matrix and name that place by its color
This is a example i hand typed
WCent =
Green Blue Red
(1 1) (2 1) (3 1)
Orange White Red
(1 2) (2 2) (3 2)
White Red Yellow
(1 3) (2 3) (3 3)
so position 3 was replaced by the color white, which was the color for the x=1 and y=3 XYColor
My intial idea was to a triple for loop along with some ifs, but I am not able to due to my beginner status

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

### 답변(1개)

darova 2021년 2월 11일
What about interpolation?
clc,clear
XYColor = [
1 3 1 1 1
1 2 1 0 1
1 1 0 1 0
2 1 0 0 1
2 2 1 1 1
2 3 1 0 0
3 1 1 0 0
3 2 1 0 0
3 3 1 1 0];
x = XYColor(:,1);
y = XYColor(:,2);
r = XYColor(:,3);
g = XYColor(:,4);
b = XYColor(:,5);
FR = scatteredInterpolant(x,y,r);
FG = scatteredInterpolant(x,y,g);
FB = scatteredInterpolant(x,y,b);
[x1,y1] = meshgrid(1:0.2:3);
r1 = FR(x1,y1);
surf(x1,y1,r1)

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

### 범주

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by