Changing axis values on Matlab figure/graph output? - matlab

I have a graph that automatically has x and y axis/values. However, I want to completely get rid of those and put into my own custom values, without changing the appearance of the graph at all.
Currently the x and y scales are pixel coordinates of the image, but I want to get rid of it and make them into centimeters so someone can better understand how large the image is that they are looking at...

You can change the units of an axes with this command:
set(YourAxesHandles,'Units','centimeters');
and then play around with the scaling/values/whatever you want:
set(YourAxesHandles,'XMin',[min max]);
set(YourAxesHandles,'YMin',[min max]);
set(YourAxesHandles,'XTick',[min:increment:max]);
and so on. Is that what you meant?

I found how to do this, check it out if you want:
% I want 8 intervals, so I divide 272 (number of pixels in X)
% by 34 to get 8 splits
set(gca,'XTick',[0:34:272])
% specify the label displayed at each tick mark
set(gca,'XTickLabel',[-4:4])
Thanks a lot, you made me look in the right direction.

Related

Change the distance between x-axis lables of a plot in MATLAB

I plot the following figure and I want to decrease the distance between x axis labels for example the distance between 1 and 2 or 2 and 3.
I do not know how can I do that !!!
I found these pages 1 and 2 but I could not know how should I write those codes without getting exceptions. Since, I am not familiar with Matlab environment.
The simple way is resize your figure or change it's position. It would change the distance.

Plot a Graph MATLAB Cell String Array vs Double

I am having a cell string array
t=({'03:00:10.000' '03:00:20.000' '03:00:30.000'});
this is actually a time array representing HH:MM:SS
and
Double numeric number array representation voltages values
b=[231.098,231.145,231.032]
now i want to draw a simple graph please help me....
i am not sure if you are just talking about those 3 values or asking for a general way to plot values vs timestamps in general. For the first case:
figurehandle = figure; % you wont need the figurehandle but just in case
axeshandle = axes; % you wont need that as well but it is nicer to code with this
plot(axeshandle,b);
axeshandle.XTick=[1 2 3];
axeshandle.XTickLabel=t;
a lot of this code can be made more general if you need it pls comment what you need
also if you dont need any of that extra handles and a shorter code
plot(b)
set(gca,'XTick',[1 2 3]);
set(gca,'XTickLabel',t);
the 'Xtick' argument determines the x values where the Ticks are placed and the 'XtickLabel' determines what every label says, so in the case of 360 data values:
set(gca,'XTick',[1 60 120 180 240 300 360]);
set(gca,'XTickLabel',t([1 60 120 180 240 300 360]));
also you are not bound to using the labels of the t vector if you dont want to you might as well use
set(gca,'XTickLabel',['3' '3:10' '3:20' 'half past 3' '3:40' '3:50' '4']);
you can get everything you want there (even latex specials), but the number of entries has to be the same as the number of tick choosen by 'XTick'. If its not about the coding for you and just about making one nice graph you might use the 'show plot tools and dock figure'-button on the matlab plot window (usually the last of the lower button-bar where you can change pretty much everything about the plot in a nice toolbox
You should use plot for drawing. Try this:
plot(t, b);

Why is errorbar whisker length dependent on X

I am running a simulation in Matlab 2015 which creates data each round, so I am plotting a number of single errorbar series individually. Here's a sample code and the output plot:
figure
xlim([0 30])
hold on
errorbar(1,2.0,1.9,16.5,'x')
errorbar(15,2.0,1.9,16.5,'x')
errorbar(25,2.0,1.9,16.5,'x')
errorbar(10,2.0,1.9,16.5,'x')
errorbar(30,2.0,1.9,16.5,'x')
errorbar(5,2.0,1.9,16.5,'x')
errorbar(20,2.0,1.9,16.5,'x')
The weirdness is that the whisker length appears to be dependent on my X value. As you can see it increases from left to right, even though I did not plot them from left to right. The single-sided width of each whisker is 0.01*x.
Why is this happening, and how can I fix it? This doesn't seem like intended functionality. Ideally I would just manually set the width of each whisker, but I can't find a way to do that. There was a function posted on the MFX a while back, but that was made for R2007b and no longer works. The errorbar series properties do not give any indication that the whiskers can even be affected at all. Any help here would be greatly appreciated!

Contouring a mesh and assigning magnitude arrows in Matlab

I want to assign vector to a contourf graph, in order to show the direction and magnitude of wind.
For this I am using contourf(A) and quiver(x,y), where as A is a matrix 151x401 and x,y are matrices with the same sizes (151x401) with magnitude and direction respectively.
When I am using large maps i get the position of the arrows but they are to densily placed and that makes the graph look bad.
The final graph has the arrows as desired, but they are to many of them and too close, I would like them to be more scarce and distributed with more gap between them, so as to be able to increase their length and at the same time have the components of the contour map visible.
Can anyone help , any pointers would be helpful
i know its been a long time since the question was asked, but i think i found a way to make it work.
I attach the code in case someone encounters the same issues
[nx,ny]= size(A) % A is the matrix used as base
xx=1:1:ny; % set the x-axis to be equal to the y
yy=1:1:nx; % set the y-axis to be equal to the x
contourf(xx,yy,A)
hold on, delta = 8; %delta is the distance between arrows)
quiver(xx(1:delta:end),yy(1:delta:end),B(1:delta:end,1:delta:end),C(1:delta:end,1:delta:end),1) % the 1 at the end is the size of the arrows
set(gca,'fontsize',12);, hold off
A,B,C are the corresponding matrices ones want to use

How would you pixelate an image in Matlab without using the image toolbox?

mypicture=imread(filename); %inputs 1st image
[row col pan]=size(mypicture);
subplot(2,1,2)
pixpicture=mypicture;
image(pixpicture);
hold on;
for J=1:stepval:row
for K=1:stepval:col
pix=pixpicture(J,K,:);
x=[K K+stepval K K+stepval];
y=[J J J+stepval J+stepval];
plot(x,y);
hold all;
end
end
subplot (2,1,1)
image(mypicture);
end
I'm trying to pixelate an image without using the image processing toolbox. I was told the method, which is to take a pixel then color all of the surrounding pixels that color, however I'm having trouble doing this in my code. What I have above is what I've tried however it doesn't quite work as intended.
What are your suggestions?
Think of each pixel as three numbers, each corresponding to how much red, green and blue that pixel has. Say pixel=[128 35 0]
You then need to use those three values and assign them to the surrounding pixels.
pixpicture(J,K,:)=pix
Where the J and K values should correspond to all the neighbors of that pixel.
Give that a go, hopefully I said enough without just giving you the answer.
Having said all of that why don't you just reduce the size of the image using
pixelatedImage = imresize(mypicture, scale)
It would be much easier than trying to do that yourself. It doesn't look like you gave a thought to the cases where you have corners or how many pixels to change in the neighborhood...