How to give color to data?

figure(1)
plot(epoch_1,Javad0081_Round_1)
hold on
k=0.5;
plot(epoch_1,k+Javad0082_Round_1)
hold off
If my data for the epoch_1 = 1:668;
Javad0081_Round_1 = 668*36; 2D data. Please see the attachment and I want to plot 669 to x axis and all 36 column on y axis mentioning that the Prn1= column1......
So during plot row will be plot and column will be plot in different column. But how to give the name as per color ? I did not mention that this color so how will mention that this color is for red -column1 , blue - column2, ..................upto 36.

Respuestas (1)

Anudeep Kumar
Anudeep Kumar el 23 de Jun. de 2025

0 votos

Hey vimal,
From what I understand you might want to explore the 'Color' and 'DisplayName' Name-Value argument of the plot function.
Given your data and what you want to achieve, the below code snippet should help you plot color wise columns in a single figure.
%Assuming epoch_1 is defined as
epoch_1 = 1:size(Javad0081_Round_1, 1);
% Create a new figure explicitly
fig = figure;
% Hold on to plot multiple lines
hold on;
% Define a colormap with 36 unique colors
colors = lines(36); % You can also try 'jet', 'parula', etc.
% Plot each PRN column
for i = 1:36
plot(epoch_1, Javad0081_Round_1(:, i), 'Color', colors(i, :), 'DisplayName', ['PRN' num2str(i)]);
end
% Add labels, title, and legend
xlabel('Epoch');
ylabel('Measurement Value');
title('PRN Measurements Over Epochs');
legend('Location', 'eastoutside');
grid on;
hold off;
I have attached the documentation of plot function especailly the 'Color' and 'DisplayName' property section for your refernce and better understanding

Categorías

Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.

Preguntada:

el 11 de Mayo de 2020

Respondida:

el 23 de Jun. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by