using image command for data with three columns
Mostra commenti meno recenti
I have a datset with three columns.
The first column contains the data of x axis points.
The second axis contains the data of y axis points.
The third column contains integer indices either 1,2,3 corresponding to each (x,y) point.
I want to color code the x-y axis according to the indices alloted to each pair (x,y) and Color array
Col = [1,1,0; 0.7,0.7,0.7; 0.929,0.694,0.125];
3 Commenti
Dyuman Joshi
il 16 Gen 2024
Do you want to plot a line plot or a scatter plot? Or something else?
Sishu Shankar
il 16 Gen 2024
Modificato: Sishu Shankar
il 16 Gen 2024
Dyuman Joshi
il 16 Gen 2024
Risposta accettata
Più risposte (1)
Hi Sishu,
If you want a scatter plot, you can loop through each index and use the scatter function to plot all the points belonging to one index along with the color corresponding to the index in each iteration.
Here is the code implementation for the same:
% Replace these with your actual data
x = [1, 2, 3, 4]; % x data
y = [5, 6, 7, 8]; % y data
indices = [1, 2, 3, 1]; % indices data
% color array
Col = [1, 1, 0; 0.7, 0.7, 0.7; 0.929, 0.694, 0.125];
figure;
hold on;
% Loop through each unique index to plot the points
for idx = 1:size(Col, 1)
% Find the points that correspond to the current index
current_points = (indices == idx);
% Scatter the points using the corresponding row from Col
scatter(x(current_points), y(current_points), [], Col(idx, :), 'filled');
end
xlabel('X axis');
ylabel('Y axis');
title('Color-coded x-y points by index');
hold off;
1 Commento
Sishu Shankar
il 16 Gen 2024
Categorie
Scopri di più su Annotations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
