Reputation: 20620
In Matlab, when I want to plot each row of a n x m matrix A
as a line, I do
plot(A');
One problem for me is the x-labels which are indices from 1 to number of variables.
I want to change those labels to more meaningful values from, say, a vector B
.
So I tried following statement
plot(repmat(B,1,size(A,1)),A');
but the chart looks totally different. I know I can use 'XTickLabel' but it does not work with line plot of matrix, meaning no effect of 'XTickLabel'. Any idea how I can put labels correctly?
Upvotes: 0
Views: 127
Reputation: 4685
You could try this as well
x = 0:0.1:1;
A = [ x.*x ; exp(-x) ]
plot( x, A' )
Upvotes: 1
Reputation: 3994
You could use something along the lines of:
>>
A = [
1 2 3 4
5 6 7 8
9 8 7 6
5 4 3 2
];
>>
B = [
15 30 45 60
];
>> plot(A')
>> set(gca, 'XTick', 1:numel(B))
>> set(gca, 'XTickLabel', cellstr(num2str(B'))')
This would give you:
Upvotes: 2