using image command for data with three columns

조회 수: 3 (최근 30일)
Sishu Shankar
Sishu Shankar 2024년 1월 16일
댓글: Sishu Shankar 2024년 1월 16일
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
Sishu Shankar
Sishu Shankar 2024년 1월 16일
편집: Sishu Shankar 2024년 1월 16일
I want to plot a color coded plot, where I already have in the third column which colour to assign to each (x,y) point.
Say, the dataset looks like
dat = [ 0.3 0.4 1
0.5 0.8 2
0.1 0.1 3
0.5 0.4 2]
Col = [1,1,0; 0.7,0.7,0.7; 0.929,0.694,0.125];
for each (x_i,y_i), i have the color z_i = Col(i) associated but I am njot sure how to implement in MATLAB
Dyuman Joshi
Dyuman Joshi 2024년 1월 16일
I understood that.
But, how should the values be plotted - should it be a scatter plot or a line plot?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2024년 1월 16일
편집: Walter Roberson 2024년 1월 16일
cmap = [1, 1, 0;
0.7, 0.7, 0.7;
0.929, 0.694, 0.125]
pointsize = [];
scatter(x, y, pointsize, third_column);
colormap(cmap);

추가 답변 (1개)

Udit06
Udit06 2024년 1월 16일
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;

카테고리

Help CenterFile Exchange에서 Purple에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by