how to plot a matrix graph of D(n,m) versus C(n,m) with different colors
Show older comments
I would like to plot a graph of D versus C. For each i have a different color
Accepted Answer
More Answers (2)
Shantanu Dixit
on 17 Jul 2024
0 votes
Hi Albert,
It is my understanding that you want to plot the two matrix values against each other and have different colors corresponding to each row in the plots.
You can use ‘plot(X,Y,LineSpec)’ from ‘plot’ functionality in MATLAB.
X cand Y point to the corresponding rows from D and C respectively. Colors can be defined using ‘colormap’ as a 12X3 matrix and be passed as LineSpec to the ‘plot’ function.
Additionally, you can refer to the following MathWorks documentation link for better understanding on plotting and colormap:
1 Comment
albert Kinda
on 17 Jul 2024
Rahul
on 17 Jul 2024
I was able to use the code you provided to obtain the plot figure. The following changes can help you get the desired plot:
- Firstly, I defined a colormap using the 'lines' function.
- Further, I made the use of 'hold on' and 'hold off' in the loop while plotting to obtain all points in the same plot.
colors = lines(12);
hold on;
for i=1:1:12
for j=1:1:49
plot(D(i,j), C(i,j), '.', 'Color', colors(i, :)); % Use different color for each i
end
end
hold off;
You can refer to this link for more information regarding 'hold' function: https://www.mathworks.com/help/releases/R2024a/matlab/ref/hold.html?searchHighlight=hold&s_tid=doc_srchtitle
You can refer to this link to style the plot according to your needs: https://www.mathworks.com/help/releases/R2024a/matlab/ref/plot.html?searchHighlight=plot&s_tid=doc_srchtitle
Hope this helps!
1 Comment
albert Kinda
on 17 Jul 2024
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!