I'm having an issue with moving the datum while plotting a 3D surface using the surf. I have a matrix RES with values < 10^-5 (e.g. RES(30,40)=0.000043245). If I plot this matrix using surf:
surf(RES); axis([0 70 0 70 0 0.0008]);
Then I get a nice smooth image.
Now I need to add a constant value of 10 to the entire matrix and then to plot it with a new datum. So I want the exact same plot as the above figure except I want the z-axis to go from 10 to 10.0008. In this case, all the numbers are more like RES(30,40)=10.000043245.
So I try it:
surf(RES+10); axis([0 70 0 70 10 10.0008]);
And I get this really chunky, blocky output.
Does anyone know why it does this? Both figures should look exactly the same shouldn't they? All I've done is move the z-axis up by 10.
Related
I have a vector of 1000 random numbers biased towards the bounds of 540 and 600. I need to plot this data as a wriggly circular path between two concentric circles of radii 540 and 600 respectively. How do I do this?
Presently, I'm able to plot the concentric circles of given radii, but if I try to plot the given random data which is between the bounds 540 and 600, it is plotted along the width between the two concentric circles. I want it to be plotted as a noisy circular curve between the concentric circles.
I hope I'm able to explain my point
If anyone can tell me, how do I do that. Thanks
Here is the link to my previous post, wherein I had to generate random numbers biased towards the two well defined bounds
Generating random numbers in matlab biased towards the boundaries
Now I need to plot the same data, as explained above.
This is the image I get:
What you actually want is a circular plot, so the first idea that comes to my mind is to use polar coordinate.
First we get your sample of around 1000 random datas biased to the bounds of your [540 600] interval following that.
Note that this algorithm will not always get you exactly 1000 values as the out of bound values are removed.
So we'll do something like this :
%Get the size of the sample
P=length(X);
% Generate P Angles uniformly distributed between 0 and 2*pi*(P-1)/P
% Note generating an angle equal to 0 and an angle equal to 2*pi would
% mean that we have 2 points with the same angle, and that s something
% you generally want to avoid
Angles=(0:P-1)*(2*pi/P);
% Plot your points with the markers (polar coordinates) in '-+',
% - means that you want a line to be drawn between the points and
% + means that you want a + marker on every point
plot(X.*cos(Angles),X.*sin(Angles),'-+');
%tell matlab to wait so you can add the circles
hold on
% add circle of 540 radius
plot(540*cos(Angles),540*sin(Angles),'-r');
%add circle of 600 radius
plot(600*cos(Angles),600*sin(Angles),'-r');
For the final result of :
Update : About getting the angles randomly distibuted
We'll have to define our Angles diffrently. We still need a vector of length P, but randomly distributed. This can be achieved by taking P random numbers between 0 and 1, and then multiply this vector by 2*pi in order to get randomly distributed values between 0 and 2*pi.
Last step is to order this vector in order to keep the ordering of your data.
Temp=rand(1,P)*2*pi;
Angles=sort(Temp);
For a final result of :
Another lead woult be to take a sample of 1000 gaussian random numbers and use them modulo 2*pi :
Angles=sort(mod(randn(1,P)*2*pi,2*pi));
so I am trying to calculate some areas on a matlab plot. Using the scatter function I get a plot like this:
The color corresponds to a fibre orientation in degrees
Now I an trying to get the area for each region of 10 degrees. For instance, I'm taking all the dots from 10 to 20 degree. Let's say I have 3 distinct regions. I want to use the convexhull to be able to extrapolate and get the area.
To be more clear, using the following loop:
c=z1>10 & z1 < 20;
c=c.*1;
for i=1:length(z1)
if z1(i)< 20 && z1(i)> 10
c(i) = 1;
else
c(i)=0;
end
end
I locate the dots in that region and replot the scatter:
Now all the red dots corresponds to angles between 10 and 20, the rest is blue. I want to be able to label each region and circle them to get the area using convexhull. I think I have to turn the thing in black and white, then enlarge each dot to circle so they touch each other, the fill any hole so you have uniform region and then apply the convexhull function. But I have no idea how to do all that. If anyone has any suggestion?
Thanks very much
EDIT: so instead of doing scatter(x1,y1,3,c,'filled')
I create a matrix B=[c c c] to get a color matrix, and then inverse the 0 and 1 by doing this B = ~B; then I get a picture like this with scatter(x1,y1,3,B,'filled') which I think I can use directly for convexhull?
This question already has answers here:
How to create a custom colormap programmatically?
(2 answers)
Closed 7 years ago.
I have a contour plot with data that goes from -90 to 90 degrees. for now i am using jet so I have a map that looks like this
I have been asked to change the colormap so that instead of having a gradient, I have a fixed color for each 5 degress (so I believe 36 colors). Also i was thinking of maybe having same colors for the interval [5 10] and [-10 -5], and so on if that makes sense.
My code is quite long because i have a lot of data to process, but that's part of it just so you can see what function i am using to plot this
%%
x1=data(:,5); %x location
y1=data(:,16); %y location
z1=phi*90; %angle phi
z2=gamma*90; %angle gamma
n=300; precision of grid
%Create regular grid across data space
[X,Y] = meshgrid(linspace(min(x1),max(x1),n), linspace(min(y1),max(y1),n));
figure(3);
contourf(X,Y,griddata(x1,y1,z1,X,Y),100,'EdgeColor', 'None')
%title('Variation of In-plane angle \phi')
axis equal
axis ([0 8000 0 12000])
axis off
h=colorbar;
caxis([-90 90])
set(h, 'YTick', [-90:15:90])
Does anyone know how to create this colorbar?
Cheers
Every colormap-generating function in Matlab, including jet, takes an argument that specifies how many colormap entries there should be. In your case, you want 180 / 5 = 36 discrete colors:
colormap(jet(36))
To make sure the 36 colors cover exactly the 5 degree steps, set the color axis explicitly:
caxis([-90 90])
The result looks e.g. like this:
I have my histogram with this appearance
And he wanted to get this way, but I don't know which fields should I change or where
I wanted to like this
How can i make this definition?
I understand you want to plot the histogram of an image in a way to limit the x axis to 255 shades of gray and y to the number of pixels in the image. This should do the work:
ima=[1 2 255;0 23 78;3 60 200;255 0 78]
plot([0:255],hist(ima(:),[0:255]))
set(gca,'xLim',[0 255])
set(gca,'yLim',[0 numel(ima)])
I have a 15x15 image of a grid of numbers which I have shown using imagesc. However, the axis goes up to 450 in both directions, when I only want it to go up to 15. I tried:
axis/30;
But that doesn't do anything? All I want to do is divide the x and y axes by 30!
The problem is, I presume, that although your image shows 15 numbers along in each axes, the total size of your image in pixels is 450 x 450 - and this is what imagesc is using.
So, what you really have is an image with 15 x 15 blocks of 30 x 30 pixels. You can set the axes ticks and labels manually using XTick and XTickLabel:
atick = 15:30:415; %assuming you want the ticks in the centre of each block
set(gca,'XTick',atick);
set(gca,'XTickLabel', 1:15);
set(gca,'YTick',atick);
set(gca,'YTickLabel', 1:15);