Hey Saneesh,
I understand that you are trying to plot multiple ellipses on a single plot and want to add a color bar that reflects the orientation of each ellipse. This involves using the orientation angle to determine the color of each ellipse, and then displaying a color bar to represent these angles visually.
To achieve this, you can:
- Normalize the orientation angles to map them to a colormap.
- Use MATLAB's "colormap" to assign colors to each ellipse based on its orientation.
- Add a color bar to the plot to indicate the mapping from angles to colors.
% Example data
PMAX1 = rand(10, 1) * 5; % Replace with your data
PMIN1 = rand(10, 1) * 3; % Replace with your data
frr = rand(10, 1) * 10; % Replace with your data
the1 = linspace(0, 2*pi, 10)'; % Replace with your data
% Prepare the figure
figure;
hold on;
colormap(jet); % Use the jet colormap for color representation
% Get the range of angles for normalization
min_alpha = min(the1);
max_alpha = max(the1);
for ut = 1:length(PMAX1)
a = PMAX1(ut, 1);
b = PMIN1(ut, 1);
uh = .15;
xc = 5;
yc = frr(ut, 1);
alpha = the1(ut, 1);
m = 1000;
x = zeros(m, 1);
y = zeros(m, 1);
theta = linspace(0, 2*pi, m);
for k = 1:m
x(k) = .2 * cos(theta(k));
y(k) = uh * sin(theta(k));
end
R = [cos(alpha) -sin(alpha); sin(alpha) cos(alpha)];
rCoords = R * [x'; y'];
xr = rCoords(1, :)';
yr = rCoords(2, :)';
% Normalize alpha to a value between 0 and 1
normalized_alpha = (alpha - min_alpha) / (max_alpha - min_alpha);
% Map the normalized alpha to a color
color = colormap(jet);
colorIndex = round(normalized_alpha * (size(color, 1) - 1)) + 1;
ellipseColor = color(colorIndex, :);
% Plot the ellipse with the assigned color
plot(xr + xc, yr + yc, 'Color', ellipseColor, 'LineWidth', 1.5);
end
% Add a color bar
colorbar;
caxis([min_alpha max_alpha]); % Set the limits of the color bar to match the angle range
xlabel('X-axis');
ylabel('Y-axis');
title('Ellipses with Orientation-Based Color');
hold off;
Explanation:
- Colormap: The "jet" colormap is used here, but you can choose any colormap you prefer.
- Normalization: The angle is normalized between 0 and 1 to map it to the colormap index.
- Color Mapping: For each ellipse, a color is selected based on its orientation.
- Color Bar: A color bar is added to the plot to indicate the orientation corresponding to the colors.
To learn more about "colormap" and "colorbar" , refer to the following MathWorks documentation:
- colormap : https://www.mathworks.com/help/matlab/ref/colormap.html
- colorbar : https://www.mathworks.com/help/matlab/ref/colorbar.html
Hope this helps!
Regards