draw the multiple-measurement training data(3D) and single predicted data(3D) in 2D

1 次查看(过去 30 天)
now my training data is
train = [
1 2 11
1 2 11
1 2 12
1 2 11
1 2 11
1 2 12
1 3 17
1 3 15
1 4 18
1 4 18
1 3 15
1 3 16
1 3 17
1 3 15
1 3 16
1 3 17
1 3 15
1 3 15
1 3 15
1 3 16
1 2 12
1 2 11
1 2 11
1 2 11
1 4 18
1 4 18
1 4 18
1 4 17
1 4 17
1 4 17
1 4 17
1 4 17
]
my predicted data is
predData= [
1 2 11.5
1 3 16
1 4 17.5
]
how to draw them together to check if my prediction value is good or not?
the follow picture is what I want to get
the difficulty is that our data is tuple
(x_coordinate,y_coordinatem,value),
If we want to draw train data and pred data together, we have to sort them in same order.
the x and y coordinates will be a new X-axis value in the figure I want to draw.
I hope x_coordinate as the first sort key word and y_coordinatem as the second sort key word.
Now I can draw predData easily,but I don't know how to draw the train data into this figure.
[lengPredData,~]=size(predData);
i = 1:lengPredData;
plot(i,predData(:,3),'o');

采纳的回答

Elizabeth Reese
Elizabeth Reese 2017-12-7
First, you can use the sortrows function to sort the train and predData matrix rows by the first and then the second columns.
Then, you can use unique to find the (x,y) coordinates that you will need to plot.
From there, you can loop through the unique coordinates and plot the points that match that coordinate. Use hold on before this code to ensure that the old plots stay on the axes when you create a new plot.
for i=1:length(coords)
p1 = plot(i,trainSort(trainSort(:,1) == coords(i,1) & trainSort(:,2) == coords(i,2),3),'ko');
p2 = plot(i,predSort(predSort(:,1) == coords(i,1) & predSort(:,2) == coords(i,2),3),'ro');
end
To change the xticklabels to be the coordinates, you can build a cell array of the strings that would go along that axis and then use xticklabels and xticks to adjust the x-axis. To create the legend, just save a handle to one of the plots (p1 and p2 above) and use the legend command. Note that p1 and p2 have distinct line object for each dot, because of the scalar expansion of i, so you need to do:
legend([p1(1) p2(1)],'train','predict');
Hope this helps!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 数据分布图 的更多信息

Community Treasure Hunt

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

Start Hunting!