# Show largest component of vector and give unique color

1 Ansicht (letzte 30 Tage)
Jeroen van Bemmel am 3 Dez. 2021
Bearbeitet: Pavan Sahith am 15 Feb. 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
% 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
end
title('max unconverged mode per blade position')
grid on
grid minor
ylabel('F_{pro}(t)-F_{rel}(t-1)')
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?
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Pavan Sahith am 15 Feb. 2024
Bearbeitet: Pavan Sahith am 15 Feb. 2024
Hello,
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;
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
% 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
end
% Create a figure
hold on; % Keep the plot for adding more points
% Plot each point with its respective color
scatter(j, MaxMode(j), [], colors(MaxModeIndex(j), :), 'filled');
end
title('Max unconverged mode per blade position');
ylabel('F_{pro}(t)-F_{rel}(t-1)');
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.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

R2020b

### Community Treasure Hunt

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

Start Hunting!

Translated by