I have the following normal distribution and i need to set the graph plot to 1.5 on y axis.
x = -.5:0.0001:3.5;
m1 = 1;
s1 = 0.5;
pdfNormal_1 = normpdf(x, m1, s1);
ylim([0 1.5])
set(gcf,'color','w');
plot(x, pdfNormal_1)%, x, pdfNormal_2);
Could someone tell me how to? Regards
The axis function is the one you need.
you can set the axis to the values you want using
axis([xmin xmax ymin ymax])
or you can play with it doing things like:
axis equal
axis tight
axis off
etc
Go to the documentation for more info:
http://www.mathworks.co.uk/help/matlab/ref/axis.html?refresh=true
Try this,
x = -.5:0.0001:3.5;
m1 = 1;
s1 = 0.5;
pdfNormal_1 = normpdf(x, m1, s1);
set(gcf,'color','w');
plot(x, pdfNormal_1)%, x, pdfNormal_2);
ylim([0 1.5])
Related
I have the following normal distribution and i need to set the graph plot to 1.5 on y axis.
x = -.5:0.0001:3.5;
m1 = 1;
s1 = 0.5;
pdfNormal_1 = normpdf(x, m1, s1);
ylim([0 1.5])
set(gcf,'color','w');
plot(x, pdfNormal_1)%, x, pdfNormal_2);
Could someone tell me how to? Regards
The axis function is the one you need.
you can set the axis to the values you want using
axis([xmin xmax ymin ymax])
or you can play with it doing things like:
axis equal
axis tight
axis off
etc
Go to the documentation for more info:
http://www.mathworks.co.uk/help/matlab/ref/axis.html?refresh=true
Try this,
x = -.5:0.0001:3.5;
m1 = 1;
s1 = 0.5;
pdfNormal_1 = normpdf(x, m1, s1);
set(gcf,'color','w');
plot(x, pdfNormal_1)%, x, pdfNormal_2);
ylim([0 1.5])
I'm trying to plot a few waveforms onto the same plot in Matlab; brand new to it. I've tried plotting them all together with plot() but it doesn't scale them all appropriately. How would I go about scaling them? I read something online that uses hold on, but I'm getting the same issue I believe. What's the simple solution here?
t1 = 0:0.1:1000;
y1 = t1.^5-5*t1.^3+4*t1;
plot(t1, y1)
hold on
t2 = 0:0.0001:0.01;
y2 = -8*exp(-1000*t2) + 3;
plot(t2, y2)
hold on
t3 = 0:0.0001:0.6;
y3 = exp(-10*t3).*cos(100*t3);
plot(t3, y3)
hold on
%plot(t1, y1, t2, y2, t3, y3)
Matlab is doing what you ask it to do: plotting everything to the same axis system (by the way, you only need to use hold on once, it is active until you change the axis or command hold off)
You have three options
define the limits of the axis explicitly, either separately using xlim([xmin xmax]) and ylim([ymin ymax]) or jointly using axis([xmin xmax ymin ymax]) (in your case e.g. axis([0 0.6 0 3.3])
you may want to use separate axis in one plot, see yyaxis yyaxis left / yyaxis right to activate the axes. Note that this only provides two different axes scales
use subplots! (as Cris Luengo already stated)
That would be in your case
% 1st subplot
t1 = 0:0.1:1000;
y1 = t1.^5-5*t1.^3+4*t1;
ax(1) = subplot(3,1,1);
plot(t1, y1)
% 2nd subplot
t2 = 0:0.0001:0.01;
y2 = -8*exp(-1000*t2) + 3;
ax(2) = subplot(3,1,2);
plot(t2, y2)
% 3rd subplot
t3 = 0:0.0001:0.6;
y3 = exp(-10*t3).*cos(100*t3);
ax(3) = subplot(3,1,3);
plot(t3, y3)
% link all axes (but only x direction)
linkaxes(ax,'x')
% your axes limits are so large that you probably don't want to link them
Using this command, axis([XMIN XMAX YMIN YMAX] we can set range of both x and y axis.
Is there any way by which only one particular axis of plot is scaled while other is set at auto-scaling?
Check xlim, ylim and zlim for manually setting the limits of every axis.
For example:
x = 0:0.1:2*pi;
y = sin(x);
plot(x,y);
XMIN = 0;
XMAX = pi;
xlim([XMIN XMAX]);
This is the output:
I have a matrix that stores x, y and z values as so:
{x1, y1, z1},
{x2, y2, z2},
{x3, y3, z3},
etc...
I need to interpolate the data, and plot in on a 2d graph, with color representing the z value. (example)
Any ideas?
Thanks!
Something like griddata might help you to interpolate:
x = vector(:,1);
y = vector(:,2);
z = vector(:,3);
% Settings
xres = 800; % Resolution, the higher, the smoother
yres = 800;
cm = 'default'; % Colormap
% Axes Limits
xmin = min(x);
ymin = min(y);
xmax = max(x);
ymax = max(y);
xi = linspace(xmin, xmax, xres);
yi = linspace(ymin, ymax, yres);
% Figure
myfig = figure('Position', [200 200 800 600]);
rotate3d off
[XI, YI] = meshgrid(xi, yi);
ZI = griddata(x, y, z, XI, YI, 'cubic');
mesh(XI,YI,ZI);
than you just need to change the view of it to only display a certain plane for a fixed value of z
In addition to #Alexandrew answer you can use newer and faster TriScatteredInterp class instead of GRIDDATA. For your exampe you can use 2D IMAGESC instead of 3D MESH.
%# insert the code from #Alexandrew answer to generate meshgrid
[XI, YI] = meshgrid(xi, yi);
TSI = TriScatteredInterp(x,y,z);
ZI = TSI(XI,YI);
imagesc(ZI)
colorbar
If your input matrix is a cell array, you can convert it to a numeric matrix with a = cell2mat(a);
I have little or no experience with volumetric data in MATLAB,
I need to complete next task:
I have 3 vectors ( rows ):
x_ = vector(1:smpl:max_row,1);
y_ = vector(1:smpl:max_row,2);
z_ = vector(1:smpl:max_row,3);
that are samples from large 3 columns array vector with height max_row.
x_ , y_ , z_ are points of 3D figure - surface points of the figure ( volume ). They represent 3D body that should be drawn in matlab.
I created linear grid:
%linear grid
a = -1.1:step:(-1.1+step*(length(x_)-1));
b = -1.1:step:(-1.1+step*(length(y_)-1));
c = -1.1:step:(-1.1+step*(length(z_)-1));
[x,y,z] = meshgrid(-1.1:step:(-1.1+step*(length(x_)-1)));
and also I create array v length(x_)*length(x_)*length(x_) that contains '1' in cells that are of 3D body representation function points and '0' another.
I tryied to make interpolation:
vi = interp3(x,y,z,v,x,y,z,'nearest');
but then vi = v that I've already created.
Now I need to plot the v array on 3D and form 3D body like in
http://www.mathworks.com/help/techdoc/ref/isonormals.html
for example.
I make that next way:
%plotting:
figure
p = patch(isosurface(x,y,z,v,1e-5,'verbose'),'FaceColor','green','EdgeColor','none');
grid on;
isonormals(v,p);
daspect([1 1 1])
view(3);
axis tight;
camproj perspective;
camlight
lighting gouraud
colormap(hsv)
but I get then only small rectangles in place of function '1' that are not connected like in picture that is attached.
I expect solid body enclosed by that points to be plotted.
Does anybody know what is the problem , how to draw 3D body from the x,y,z,v arrays ?
Thanks in advance.
image:
http://imgur.com/Ulegj
Try this, which will be a nice plot (it interpolates a bit though):
x = vector(1:smpl:max_row,1);
y = vector(1:smpl:max_row,2);
z = vector(1:smpl:max_row,3);
% Settings
displaySurface = 1;
displayPoints = 0;
xres = 800; % Resolution, the higher, the smoother
yres = 800;
cm = 'default'; % Colormap
% Axes Limits
xmin = min(x);
ymin = min(y);
xmax = max(x);
ymax = max(y);
xi = linspace(xmin, xmax, xres);
yi = linspace(ymin, ymax, yres);
% Figure
myfig = figure('Position', [200 200 800 600]);
rotate3d off
[XI, YI] = meshgrid(xi, yi);
ZI = griddata(x, y, z, XI, YI, 'cubic');
mesh(XI,YI,ZI);
colormap(cm)
if(displaySurface == 1)
hold on;
surf(XI, YI, ZI, 'EdgeColor', 'none');
end
hold on;
xlabel('x');
ylabel('y');
zlabel('z');
title('Title', 'FontWeight', 'bold');
xlim([xmin xmax])
ylim([ymin ymax])
grid off;
if(displayPoints == 1)
hold on
plot3(x, y, z,'marker','p','markerfacecolor','w','linestyle','none')
hidden off
end