Reputation: 219
I have arbitrary points (X,Y) to which, has two corresponding eigenvalues.
I have decided to categorize the eigenvalues in to three categories, namely:
I would like to plot it out, color coding each point (X,Y), on the X-Y plane with a different colour.
I have used imagesc but it does not show the X-Y plane.
Here is a sketch of what I'm trying to get, where the colour coding indicates the scenerio of the eigenvalue obtained for that particular (X,Y).
p.s. Pardon me, there should be 1 more case, i.e. 1 eigenvalue > 0 , 2nd eigenvalue < 0
Could someone direct me to where I can read up more about this?
Edit: Here is my code.
vecStor is a 2 x n matrix storing the eigenvalue in each corresponding row.
%e.g vecStor = [ 1 2 3 ; 4 5 6]
%eigenvalues 1 and 4 corresponds to (X1,Y1)
%eigenvalues 2 and 5 corresponds to (X2,Y2)
Next I assigned a value to each "case" and where l is the counter for the for loop to run through the vecStor
if (vecStor(1,l) < 0 && vecStor(2,l) < 0)
fprintf('Double Neg\n')
colourStore(l,1) = -3;
else if (vecStor(1,l) > 0 && vecStor(2,l) > 0)
fprintf('Double Pos\n')
colourStore(l,1) = +3;
else if (vecStor(1,l) > 0 && vecStor(2,l) < 0)
fprintf('One Pos One Neg!\n')
colourStore(l,1) = -1;
else if (vecStor(1,l) == 0 || vecStor(2,l) == 0)
fprintf('One Zero!\n')
colourStore(l,1) = +1;
Finally I plot it out
img=colourStore';
imagesc(img);
axis image;
Upvotes: 2
Views: 414
Reputation: 4648
The input data (vecStore
) should be 3 dimensional vector with dimensions NxMx2
, where N
is the number of rows (or Y height), M
is the number of columns (or X width) and the third dimension has size 2 (for two eigenvalues per X/Y value). Let's create a random matrix representing your eigenvalues:
numRows = 10;
numColumns = 10;
vecStor = randn(numRows,numColumns,2);
Then you check for the conditions of every element in the matrix, similar to what you did in your code snippet. Loop through all rows and columns and create a two-dimensional color-map that contains four distinct values according to the eigenvalue properties:
colourStore = zeros(numRows,numColumns);
for r = 1:size(vecStor, 1)
for c = 1:size(vecStor, 2)
if (vecStor(r,c,1) < 0 && vecStor(r,c,2) < 0)
% Double Neg
colourStore(r,c) = -3;
elseif (vecStor(r,c,1) > 0 && vecStor(r,c,2) > 0)
% Double Pos
colourStore(r,c) = +3;
elseif (vecStor(r,c,1) > 0 && vecStor(r,c,2) < 0)
% First Pos, Second Neg
colourStore(r,c) = -1;
elseif (vecStor(r,c,1) == 0 || vecStor(r,c,2) == 0)
% One Zero
colourStore(r,c) = +1;
end
end
end
Finally, plot colourStore
as color image:
imagesc(colourStore);
Example output:
Here's a way to do the categorization without loops, using logical indexing:
colourStore(vecStor(:,:,1) < 0 & vecStor(:,:,2) < 0 ) = -3;
colourStore(vecStor(:,:,1) > 0 & vecStor(:,:,2) > 0) = 3;
colourStore(vecStor(:,:,1) > 0 & vecStor(:,:,2) < 0) = -1;
colourStore(vecStor(:,:,1) == 0 | vecStor(:,:,2) == 0) = 1;
Upvotes: 1