During the answering this question and issues, unrelated to the question, with creating figures with really high height I've found that figures are cropped. If 'units' properties of figure's children is set to 'normalized' the appropriate child is shrunk rather than cropped.
The question is, why is the height of figure limited and what (property) rules that limit. It looks like I'm limitted to figure height of 9.94" (Dell Latitude E5500; Win7 enterpise, 32-bit; matlab 2011b; resolution 1400x900 px)
Edit
I tried this:
>> set(gcf,'position',[10 10 600 600]),get(gcf,'position')
ans =
10.0000 10.0000 28.3333 9.8750
>> set(gcf,'position',[0 0 600 600]),get(gcf,'position')
ans =
0 0 600 600
The figure obtained by export_fig is in both cases 28.35" x 9.88" as measured in Adobe acrobat 9 Pro.
I suspect it has to do with with the maximum display size detected by Matlab and the pixel density of your system.
On my Matlab R2013a, Windows 7, with a screen 1900x1200, I can get a bigger figure than you, but it will still be truncated:
%% // MATLAB R2013A - Windows 7, 1900x1200pixels
set(gcf,'units','inches','position',[1 -5 6 15])
get(gcf,'position')
get(gcf,'OuterPosition')
returns:
ans =
1.00 -5.00 6.00 11.81
ans =
0.92 -5.08 6.17 12.71
My maximum vertical figure size was cut at 11.81 inches. Now that is the inside of a Matlab figure. The real size including the title bar and borders is given by the property OuterPosition.
Now consider:
>> get(0,'ScreenSize')
ans =
1.00 1.00 1920.00 1200.00
>> get(0,'ScreenPixelsPerInch')
ans =
96.00
If we do 1200pixel/96ppi=12.5. With this screen density, Matlab can only display 12.5 inches worth of graphics. This will be even mode obvious if you set the unit to 'Pixels':
set(gcf,'units','inches','position',[1 -5 6 15])
set(gcf,'units','Pixels')
get(gcf,'position')
get(gcf,'OuterPosition')
ans =
97.00 -479.00 576.00 1134.00
ans =
89.00 -487.00 592.00 1220.00
The figure was truncated at exactly 1220pixels (the inches unit is just a conversion, Matlab base unit will work in pixels). I suspect the extra 20 pixels allowed are an extra allowance for the title bar.
Now with your numbers, I do not have the outerposition of your figure, but even the figure inner position does match roughly your screen dimension (900px*96ppi=9.375inches). Try to force the units back to Pixels, get the OuterPosition of the figure and I wouldn't be surprised if you get 920pixels.
Now it seems you only need to worry about that for older versions of Matlab. On the same machine (Win 7, 1900x1200px), with Matlab R2015b, no more automatic cropping:
%% // MATLAB R2015B - Windows 7, 1900x1200pixels
set(gcf,'units','inches','position',[1 -5 6 15])
get(gcf,'position')
get(gcf,'OuterPosition')
ans =
1.00 -5.00 6.00 15.00
ans =
0.92 -5.08 6.17 15.40
set(gcf,'units','Pixels')
get(gcf,'position')
get(gcf,'OuterPosition')
ans =
97.00 -479.00 576.00 1440.00
ans =
89.00 -487.00 592.00 1478.00
The new graphic engine of Matlab seem to have lifted that restriction, my figure is now bigger that my screen size (whether you look at pixels or inches).
Related
I have two vectors that describe a histogram: bin values/labels and bin count.
I'd like to import those into a Matlab histogram object so that I can change parameters more easily, such as the number of bins.
Here is a simplification what I have:
Center bin values:
BinValues(1:21) = [-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10];
and count values per bin
CountValues(1:21) = [ 16 12 3 21 7 8 2 6 0 3 4 6 1 8 3 25 16 5 7 10 16];
My actual histogram has 800000 bins, and I want to vary the number of bins.
In my simplified example above, it would be something like reducing the bins from 21 to 15 or 21 to 11.
What I have can be graphed as a simple bar graph.
bar(BinValues,CountValues);
But, if I want to experiment with different numbers of bins, I think it would be best to use the histogram function/object in Matlab, but I'm not sure how I do this from what I have.
OK Update:
I tried this:
h=histogram('BinEdges',[-10.5:10.5] , 'BinCounts', CountValues);
Now I have a nice histogram, but if I use fewerbins(h), I get an error saying I can't do that while BinCountsMode is in "manual". If I modify it to be in "auto" mode, then my original histogram disappears.
The brute force solution would be to generate a huge array with repeated values as dictated by binCount values, but that seems like a dumb way to solve this problem.
Does anyone know how Matlab’s Z=dist(W,P) works? The Matlab documentation does not specify an algorithm that uses the weight matrix, W.
I am using Octave and trying to mimic the behavior. So far, this stack overflow post helped me to prove that Octave’s Z=squareform(pdist(P')) is equivalent to Matlab’s Z=dist(P). I can also designate the elements of Z using a couple of for loops:
function z=dist(w,p)
for i=1:size(p,2)
for j=1:size(p,2)
u=p(:,i);
v=p(:,j);
z(i,j)=sum((u-v).^2).^0.5;
end
end
end
However, I am unable to find any online documentation on the weight matrix, W. I cannot simply multiply the output of squareform(pdist(P')) by W because the dimensions do not match. I have attempted to premultiply W, e.g. sqrt(W*(P(:,1)-P(:,2)).^2), like this stack overflow post but the output magnitudes are wrong.
Here is an example using Matlab:
P=
9 7 10
10 1 10
2 3 2
10 6 10
W=
10 9 5 8
5 2 10 10
>> D = dist(P)
0 10.0995 1.0000
10.0995 0 10.3441
1.0000 10.3441 0
>> D = dist(W,P)
3.8730 9.0000 3.7417
12.0000 8.3666 12.3693
Thanks in advance for any help you can provide!
It appears the Neural Network Toolbox is implemented in Matlab itself, so you can just look at those source files and figure it out.
If you open dist by entering edit dist in the command window, you see that it calls dist.apply or dist.distance to do the actual work, and the latter again dist.apply. Therefore, my guess is that what you are looking for can be found on line 9 of
toolbox/nnet/nnet/nndistance/+dist/apply.m
Type edit dist.apply in the command window to see it.
I use matlab to plot a graph where instead of having x-axis increase monotonically, I have my own values. eg 5 14 8 9 12 7 etc.I use set (gca,'XTickLabel',num2str(mydata)) which generally works. However, when mydata is more than four or five digits, Matlab scales the graph and thus x-axis values no longer correspond to their intended points. Any ideas on how to prevent this scaling? To clarify, when I make the figure larger, it shows the plot as it should.
The problem is in your num2str() conversion:
mydata = 1:10;
num2str(mydata)
ans =
1 2 3 4 5 6 7 8 9 10
This means, that each tick will be labelled with this long 1 by n char array. The axes will then be resized to fit the labels inside the figure.
A solution is to create one label per row of a char array:
reshape(sprintf('%2d',mydata),2,[])'
ans =
1
2
3
4
5
6
7
8
9
10
Sort of solution is to write set(gca,'xtick',1:myDataVectorLength) before set (gca,'XTickLabel',num2str(mydata))
So I have a table of values
v=0 1 2 3 4 5 6 7 8 9
#times obs.: 5 19 23 21 14 12 3 2 1 0
I am supposed to calculate chi squared assuming the data fits a poisson dist. with mean u=3.
I have to group values >=6 all in one bin.
I am unsure of how to plot the poisson dist., and most of all how to control what goes into what bin, if that makes sense.
I have plotted a histogram using histc before..but it was with random numbers that I normalized. The amount in each bin was set for me.
I am super new...sorry if this question sucks.
You use bar to plot a bar graph in matlab.
So this is what you do:
v=0:9;
f=[5 19 23 21 14 12 3 2 1 0];
fc=f(find(v<6)); % copy elements where v<=6 into a new array
fc(end+1)=sum(f(v=>6)); % append the sum of elements where v=>6 to that array
figure
bar(v(v<=6), fc);
That should do the trick...
Now you didn't actually ask about the chi squared calculation. I would urge you not to put values of v>6 all into one bin for that calculation, as it will give you a really bad result.
There is another technique: if you use the hist function, you can choose the bins - and Matlab will automatically put things that exceed the limits into the last bin. So if your observations were in the array Obs, you can do what was asked with:
h = hist(Obs, 0:6);
figure
bar(0:6, h)
The advantage is that you have the array h available (frequencies) for other calculations.
If you do instead
hist(Obs, 0:6)
Matlab will plot the graph for you in a single statement (but you don't have the values...)
This is a question about Matlab/Octave.
I am seeing some results of the medfilt1(1D Median filter command in matlab) computation by which I am confused.
EDIT:Sorry forgot to mention:I am using Octave for Windows 3.2.4. This is where i see this behavior.
Please see the questions below, and point if I am missing something.
1] I have a 1D data array b=[ 3 5 -8 6 0];
out=medfilt1(b,3);
I expected the output to be [3 3 5 0 0] but it is showing the output as [4 3 5 0 3]
How come? What is wrong here?
FYI-Help says it pads the data at boundaries by 0(zero).
2] How does medfilt2(2D median filter command in matlab) work.
Help says "Each output pixel contains the median value in the m-by-n neighborhood around the corresponding pixel in the input image".
For m=3,n=3, So does it calculate a 3x3 matrix MAT for each of input pixels placed at its center and do median(median(MAT)) to compute its median value in the m-by-n neighbourhood?
Any pointers will help.
thank you. -AD
I was not able to replicate your error with Matlab 7.11.0, but from the information in your question it seems like your version of medfilt1 does not differentiate between an odd or even n.
When finding the median in a vector of even length, one usually take the mean of the two median values,
median([1 3 4 5]) = (3+4)/2 = 3.5
This seems to be what happens in your case. Instead of treating n as odd, and setting the value to be 3, n is treated as even and your first out value is calculated to be
median([0 3 5]) = (3+5)/2 = 4
and so on.. EDIT: This only seems to happen in the endpoints, which suggest that the padding with zeros is not properly working in your Octave code.
For your second question, you are almost right, it calculates a 3x3 matrix in each center, but it does not do median(median(MAT)), but median(MAT(:)). There is a difference!
A = [1 2 3
14 5 33
11 7 13];
median(median(A)) = 11
median(A(:)) = 7