3 dataset plot in single dimension plane

Hello there,
I have facing a problem while plotting a data set.
I have three variables,
a,b and c.
I am trying to plot c with respect to a and b.
could you please figure out this situation.

Réponses (2)

Hi Suraj, you can use mesh, surf, contour and many others functions (see https://fr.mathworks.com/help/matlab/visualize/representing-a-matrix-as-a-surface.html). For instance:
[x, y] = meshgrid(0:0.05:pi, 0:0.05:1);
c = exp(-2*y).*sin(-x);
figure
surf(x, y, c);
xlabel('x') ; ylabel('y') ; zlabel('c');

5 commentaires

suraj karki
suraj karki le 13 Avr 2022
Thank you for your response, Riccardo Scorretti
However, I want in 1-D.
Ok. In 1-D you could make this:
x0 = 0:0.05:pi;
y0 = 0:0.1:1;
[x, y] = meshgrid(x0, y0);
c = exp(-2*y).*sin(-x);
figure
plot(x', c');
xlabel('x') ; ylabel('c');
lgnd = {};
for n = 1 : numel(y0)
lgnd{n} = sprintf('y = %4.2f', y0(n));
end
legend(lgnd{:});
Could you make a sketch of what you would like to obtain?
suraj karki
suraj karki le 13 Avr 2022
Sure,
For an example
c = [0.001 0.002 0.003 0.00021 0.0025]
a = [65 45 35 55 33]
b = [80 114 85 90 95]
Now, I need to plot c with respect to a and b. which means a and b have a co-relation to produce data c.
I hope you will understand this situation.
It is still unclear to me (sorry).
Method #1: you could plot a and b as a function of c, instead of c as a function of a and b:
c = [0.001 0.002 0.003 0.00021 0.0025];
a = [65 45 35 55 33];
b = [80 114 85 90 95];
[~, ind] = sort(c);
figure
yyaxis left
plot(c(ind), a(ind), 'o-') ; xlabel('c') ; ylabel('a');
yyaxis right
plot(c(ind), b(ind), 's-') ; ylabel('b');
The information is the same, but I guess it is not what you want.

Connectez-vous pour commenter.

Riccardo Scorretti
Riccardo Scorretti le 14 Avr 2022
Modifié(e) : Riccardo Scorretti le 14 Avr 2022
Method #2: use circles of different size to represent the value of c. I hope at least it will inspire you.
c = [0.001 0.002 0.003 0.00021 0.0025];
a = [65 45 35 55 33];
b = [80 114 85 90 95];
% This parameter controls the average size of circles (just for aestetic purpose)
% I'm afraid it has to be adjusted manually depending on the number of
% points to plot and on the orders of magnitude of a and b
fact = 0.1;
figure
sz = fact*max(abs([a(:) ; b(:)])) / max(abs(c(:))); % = characteristic size to draw circles
sz_b = 0.01*max(abs(b));
t_ = linspace(0, 2*pi, 256);
assert(numel(a) == numel(b) && numel(a) == numel(c), 'a, b, and c must have the same number of elements');
for n = 1 : numel(c)
patch(a(n)+sz*c(n)*cos(t_), b(n)+sz*c(n)*sin(t_), 'r', ...
'EdgeColor', 'k', 'FaceAlpha', 0.4);
hold on
text(a(n), b(n)+sz*c(n)+sz_b, num2str(c(n)));
end
axis square ; box on ; grid on
xlabel('a') ; ylabel('b');

Catégories

En savoir plus sur Images dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by