필터 지우기
필터 지우기

3 dataset plot in single dimension plane

조회 수: 1 (최근 30일)
suraj karki
suraj karki 2022년 4월 13일
편집: Riccardo Scorretti 2022년 4월 14일
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.

답변 (2개)

Riccardo Scorretti
Riccardo Scorretti 2022년 4월 13일
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
suraj karki
suraj karki 2022년 4월 13일
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.
Riccardo Scorretti
Riccardo Scorretti 2022년 4월 14일
편집: Riccardo Scorretti 2022년 4월 14일
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.

댓글을 달려면 로그인하십시오.


Riccardo Scorretti
Riccardo Scorretti 2022년 4월 14일
편집: Riccardo Scorretti 2022년 4월 14일
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');

Community Treasure Hunt

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

Start Hunting!

Translated by