Effacer les filtres
Effacer les filtres

Show largest component of vector and give unique color

1 vue (au cours des 30 derniers jours)
Jeroen van Bemmel
Jeroen van Bemmel le 3 Déc 2021
Modifié(e) : Pavan Sahith le 15 Fév 2024
i have 40 vectors of 5 components, and want to give the maximum of each of the 40 vectors a different color.
In this case it involves modeshapes, so lets say if mode 1 is biggest, make a yellow dot, if mode 2 is biggest give a blue dot
my code so far:
iter = 28; % number of iterations
Blade_pos = 40; % number of bladepositions in one revolution
for j=1:Blade_pos % number of blade
% here are calculations not relevant for this question
MaxMode(j) = max(deltaKT_plot(:,iter)); %in deltaKT the error of the 5 modes is stored, so i extract the largest one
plot(Blade_posvec,MaxMode) %blade_posvec is just a vector for 1 to # of blade positions
title('max unconverged mode per blade position')
xlabel('Blade Position')
grid on
grid minor
So this gives the 40 largest DeltaKTs which is one of the 5 modes,
How can i automate the process to plot modes with different colors?
Thanks in advance

Réponses (1)

Pavan Sahith
Pavan Sahith le 15 Fév 2024
Modifié(e) : Pavan Sahith le 15 Fév 2024
I can understand that you are trying to plot the maximum component of each of the 40 vectors with a unique color for each mode.
For that, you can use the "scatter" function in MATLAB, which allows you to specify the color of each point individually. You will need to determine not only the maximum value but also the index of the maximum value for each vector to decide the color.
For better understanding , you can try the following sample MATLAB code.
iter = 28;
Blade_pos = 40;
MaxMode = zeros(1, Blade_pos); % Preallocate for speed
MaxModeIndex = zeros(1, Blade_pos); % Store the index of the max mode
% Define colors for each mode
colors = [1 1 0; 0 0 1; 0 1 0; 1 0 0; 0 1 1]; % yellow, blue, green, red, cyan
for j = 1:Blade_pos
% Assuming deltaKT_plot is a Blade_pos x 5 matrix with the error of the 5 modes
[MaxMode(j), MaxModeIndex(j)] = max(deltaKT_plot(j, iter)); % Get the max value and its index for the j-th blade position
% Create a figure
hold on; % Keep the plot for adding more points
% Plot each point with its respective color
for j = 1:Blade_pos
scatter(j, MaxMode(j), [], colors(MaxModeIndex(j), :), 'filled');
title('Max unconverged mode per blade position');
xlabel('Blade Position');
grid on;
grid minor;
hold off;
% Optionally, add a legend if needed
legend('Mode 1', 'Mode 2', 'Mode 3', 'Mode 4', 'Mode 5');
In this code snippet:
  • 'MaxMode' is a vector storing the maximum value of the error for each blade position.
  • 'MaxModeIndex' is a vector storing the index of the mode that corresponds to the maximum value.
  • 'colors' is a matrix where each row represents an RGB color for a mode. You can add more colors if you have more than 5 modes.
  • The 'scatter' function is used within a loop to plot each maximum value with the color corresponding to the mode index.
To know more about the "scatter" function. you can refer to the following MathWorks documentation.
Hope this will help.


En savoir plus sur Line Plots dans Help Center et File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by