Reputation: 856
I have this situation and I can't solve it in the proper way. The problem is this: I have 3 vectors:
I want to do the following in matlab:
1- Put Vector 1 in Y axis with names - I could do it with this code:
set(gca, 'YTick',1:N, 'YTickLabel',Names(:,1))
2- put Vector 2 in X axis with, to simulate time line
3- Once we have both axis X&Y I'd like to use the 3 Vector to plot point in the graph
For example, 3 Vector contains secuentially timestamps and in each timestamp is executed the nameN, so I'd like to plot a dot in the graph using 3 vector as input.
Any suggestion?Thanks in advance
Upvotes: 0
Views: 3077
Reputation: 74940
You need to convert the names in vector3
to numbers, then you can call the plot
command.
For example
names = {'a','b','c','d'}; %# use a cell array (curly brackets) for strings
time = [10 20 30 40 50];
data = {10,'d';20,'b';40,'c'}
%# convert data to numeric xData, yData
xData = cell2mat(data(:,1));
[dummy,yData] = ismember(data(:,2),names);
%# plot
plot(xData,yData,'.') %# plot dots
set(gca,'YTick',1:length(names),'YTickLabel',names,'XTick',time)
%# make sure the axes limits aren't too tight
xlim([0,60]),ylim([0,5])
Upvotes: 1
Reputation: 2322
One way to do it is,
Also I suggest to rename vector1 to "scale", vector2 to "time", and vector3 to "values". That should help to get your mind clear about what you are using with what etc. Hope this helps.
Upvotes: 0