Div
Div

Reputation: 121

Matlab: Scale data, to plot multiple vectors on a single graph

I want to plot the following, on one single scaled graph. Here is my data and single plots of this data:

A = [11 115 167 44 51 5 6];
B = [100 1 1 87];
C = [2000 625];
D = [81 623 45 48 6 14 429 456 94];
E = [89];
F = [44 846 998 2035 498 4 68 4 1 89];

G = {A,B,C,D,E,F};
[max_val, idx] = max(cellfun(@numel, G)); % Find max sizes of vectors

figure(1);plot(1:numel(A),A,'*');
figure(2);plot(1:numel(B),B,'*');
figure(3);plot(1:numel(C),C,'*');
figure(4);plot(1:numel(D),D,'*');
figure(5);plot(1:numel(E),E,'*');
figure(6);plot(1:numel(F),F,'*');

How do I use max_val to represent 100%, in order to scale my x-axis data into a single graph. The result should be a single graph, with an x-axis of 0 to 100% (Thus the first value in the vector should represent 0%, and the last value in a vector should represent 100%), and y-values are unchanged.

In this case max_val is 10, and represents vector F. This should thus be the one graph that does not need to be scaled. All other graphs should thus be stretched out(scaled) on the x-axis, to be plotted on the same graph.


To explain with pictures, here is a conventional unscaled plot of all the data points on the same graph:

enter image description here

Here is the approximate result I want, which is a scaled plot of all the data points on the same graph (Achieved with manual excel tampering):

enter image description here

I hope this is clear. All help is appreciated.

Upvotes: 1

Views: 227

Answers (1)

Till
Till

Reputation: 453

Still, not 100% sure if I understood, what you want. But if you just want to have your x-Axis for each field in your cell between 0 and 100%, I recommend you the rescale function:

A = [11 115 167 44 51 5 6];
B = [100 1 1 87];
C = [2000 625];
D = [81 623 45 48 6 14 429 456 94];
E = [89];
F = [44 846 998 2035 498 4 68 4 1 89];
G = {A,B,C,D,E,F};

xScaled = cellfun(@(x) rescale(1:length(x),0,100),G,'UniformOutput',false);

for i = 1:length(G)
    plot(xScaled{i},G{i},'*')
    hold on
end

Upvotes: 2

Related Questions