I'm not sure if this is possible, but given the following in MATLAB:
a = [1 2 3]
b = [3 1 2]
G = Graph(a,b)
x = [0 0 1]
y = [0 1 0]
z = [1 0 0]
plot(G, 'XData', x, 'YData', y, 'ZData', z)
The plot can be outputted into a .fig file. The goal would be to turn this into any sort of mesh file, such that it outputs into just nodes and edges, but no surfaces (or create small, cylindrical surfaces as edges).
Related
I shaded the area between two lines, it's not very clean:
area(xData,[Y1(:) ,Y2(:)-Y1(:)]); hold on
colormap([1 1 1; 0 0 1]);
How to make it transparent too in MATLAB? So that it comes like:
ref:peltiertech.com
You can use the FaceAlpha property of the area object to set the transparency level:
xData = 1:7;
Y1 = [3 2 1 4 3 2 1];
Y2 = [8 6 9 8 7 5 6];
area(xData, Y2, 'EdgeColor',[0 .447 .741], 'FaceColor',[0.929 .694 .125], 'FaceAlpha',.3);
hold on
area(xData, Y1, 'EdgeColor',[0 .447 .741], 'FaceColor', [1 1 1]);
A cleaner approach is to use patch instead of area:
h = patch([xData xData(end:-1:1) xData(1)], [Y1 Y2(end:-1:1) Y1(1)], 'b');
set(h, 'EdgeColor',[0 .447 .741], 'FaceColor',[0.929 .694 .125], 'FaceAlpha',.3)
Is there a way to vectorize/accelerate the task of plotting multiple lines with different colors?
The working-but-slow approach is
X = [1 2; 3 4];
Y = [2 -4; 5 2];
figure;
hold on;
colors = [1 0 0; 0 1 0];
for idx = 1:size(X, 2)
l = plot(X(:, idx), Y(:, idx), 'Color', colors(idx, :));
end
hold off;
I tried
X = [1 2; 3 4];
Y = [2 -4; 5 2];
figure;
plot(X, Y, 'Color', [1 0 0; 0 1 0]);
but no luck.
This is probably too hacky to be a useful replacement of the loop, but here it goes:
set(gca, 'ColorOrder', [1 0 0; 0 1 0], 'NextPlot', 'add')
plot(X, Y);
The 'ColorOrder' property contains the colors to be used by default for new plots. Setting 'NextPlot' to 'add' seems to be necessary so that the call to plot doesn't reset 'ColorOrder' to its default value.
Tested on R2015b.
I have three vectors of data; first column is axis x, second column axis y and third column is the measured data point value v:
x = [1 2 3 4 5];
y = [2 3 4 5 6];
v = [0 -1 +2 3 -5];
Is there a way to plot this in matlab and color the data points according to their value? I tried with scatter, but that doesn't give color coding.
Just use scatter, it can accept values for each point. Just set the size of each point, set it to be filled, turn on the colorbar and that's it. Just please don't use the jet colormap...
x = [1 2 3 4 5];
y = [2 3 4 5 6];
v = [0 -1 +2 3 -5];
pt_sz = 30;
colormap parula
scatter(x, y, pt_sz, v, 'filled');
colorbar;
grid on
You can try pcolor. It works like
z=rand(4,4);
pcolor(R,C,z);
Where z is a matrix storing the data (your v), R is the row (your x) and C is the column (your y).
In matlab 2014b, I want to make a heatmap and then overlay a line plot using the right y-axis. For example
colormap bone
data = rand(6);
imagesc(data)
ax = gca;
ax.XTick = [1 2 3 4 5 6];
ax.YTick = [1 2 3 4 5 6];
hold on
Now plot a line but use the right y-axis because this has negative values:
x2 = [1 2 3 4 5 6];
y2 = [-0.0001 -0.0997 -0.1997 -0.2995 -0.3994 -0.4995];
plot(x2,y2,'r')
You can make it with a variation of plotyy where the first plot is composed of NaNs.
Here is the code:
hold on
colormap bone
data = rand(6);
imagesc(data)
ax = gca;
yT = ax.YTick;
x2 = [1 2 3 4 5 6];
y2 = [-0.0001 -0.0997 -0.1997 -0.2995 -0.3994 -0.4995];
[ax, ~, h] = plotyy(yT*NaN, yT, x2,y2);
ax(1).YLim = [yT(1)-0.5 yT(end)+0.5];
ax(1).YTick = yT;
ax(1).YColor = [0 0 0];
set(h, 'Color', 'r');
ax(2).YColor = [1 0 0];
ax(2).YTick = -0.5:0.1:0;
and the result:
Best,
I have made the following program for calculating the vector projection:
a=[6 7]
b=[1 4]
p=(dot(a,b)/(b*b'))*b
the result of p is [2 8] that is the projection of a on b.
I read that for plotting a vector in Matlab I should choose some origin points, so I have added those to the vectors and form a set of matrices with them like this:
x=[0 0; 6 7]
y=[0 0; 1 4]
z=[0 0; 2 8]
plot3(x,y,z)
grid;
but I cannot get to visualize the projection, what am I missing?
Thanks
You can use quiver for 2D vector plotting or quiver3 for 3D plotting.
a = [6 7];
b = [1 4];
p = (dot(a,b)/dot(b,b))*b;
figure;
quiver(0,0,a(1), a(2));
hold on;
quiver(0,0,b(1), b(2));
quiver(0,0,p(1), p(2));