Help sorting a matrix into other matrix
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
darova
on 11 Feb 2021
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)
0 Comments
See Also
Categories
Find more on Resizing and Reshaping 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!