How to plot a 3d graph in Matlab with my data? - matlab

Right now I am doing a parameter sweep and I am trying to convert my data to a 3D graph to show the results in a very nice fashion. The problem is that I don't quite know how to plot it as I am having an issue with the result variable.
mute_rate = [0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625]
mute_step = linspace(-2.5, 2.5, 6)
results = [949.58, 293.53, 57.69, 53.65, 293.41, 1257.49;
279.19, 97.94, 32.60, 29.52, 90.52, 286.94;
32.96, 28.06, 19.56, 6.44, 13.47, 55.80;
2.01, 1.52, 5.38, 1.00, 0.89, 1.41;
0.61, 0.01, 18.59, 0.03, 0.56, 1.22;
1.85, 1.51, 18.64, 18.57, 18.54, 6.90]
So the first row in the result variable presents the results of the mute rate and mute step performed on the population from my genetic algorithm. For example:
0.5, -2.5 = 949.58,
0.5, -1.5 = 293.53,
0.5, -0.5 = 57.69
etc

It sounds like you want something akin to:
mesh(mute_step, mute_rate, results);
shading interp;
Other styles of plot would be surf or pcolor (for a 2d view).

Related

MATLAB-Patch between prediction bounds?

I have some data fitted to an exponential function (y1) using the curve fitting app to calculate the coefficients. I then imported the model and the prediction intervals (p11; a 1441x2 matrix). (t and Asiii are imported datasets, just generated some data to explain the code)
S=[0.95,0.87,0.83,0.73,0.62,0.51,0.41,0.31,0.22,0.04,0.002,0,0,0,0];
t=[1,3,5,10,20,30,40,50,60,90,120,180,240,360,1440];
hold on
s2=scatter(t,Asiii,250,[0.1216, 0.8, 0.0157],'^','filled');
x = 0:1440;
y1 = 1.016*exp(-0.02349*x)
p1=plot(x,y1,'Color',[0.1216, 0.8, 0.0157],...
'LineWidth',1.5);
p11 = predint(model,x,0.95,'observation','on');
plot(x,p11,'--','Color',[0.4235, 0.9608, .6],...
'LineWidth',1.5);
%Patch
patch([x;x],[p11(:,1)';p11(:,2)'],'g');
%Fill
fill(x, p11,p11,'facecolor', 'red', 'edgecolor', 'none', 'facealpha', 0.4);
I want to have the area between the prediciton bounds/confidence intervals filled with a different color, but it seems I can only get a solid black shading using 'patch'.
I also tried using the 'fill' function but the polygons go all the way to the top of y-axis. Is there a way to adjust the Edge thickness/color?

How to calculate mean of function in a gaussian fit?

I'm using the curve fitting app in MATLAB. If I understand correctly the "b1" component in the left box is the mean of function i.e. the x point where y=50% and my x data is [-0.8 -0.7 -0.5 0 0.3 0.5 0.7], so why is this number in this example so big (631)?
General model Gauss1:
f(x) = a1*exp(-((x-b1)/c1)^2)
Coefficients (with 95% confidence bounds):
a1 = 3.862e+258 (-Inf, Inf)
b1 = 631.2 (-1.117e+06, 1.119e+06)
c1 = 25.83 (-2.287e+04, 2.292e+04)
Your data looks like cdf and not pdf. You can use this code for your solution
xi=[-0.8,-0.7,-0.5, 0.0, 0.3, 0.5, 0.7];
yi= [0.2, 0.0, 0.2, 0.2, 0.5, 1.0, 1.0];
fun=#(v) normcdf(xi,v(1),v(2))-yi;
[v]=lsqnonlin(fun,[1,1]); %[1,2]
mu=v(1); sigma=v(2);
x=linspace(-1.5,1.5,100);
y=normcdf(x,mu,sigma);
figure(1);clf;plot(xi,yi,'x',x,y);
annotation('textbox',[0.2,0.7,0.1,0.1], 'String',sprintf('mu=%f\nsigma=%f',mu,sigma),'FitBoxToText','on','FontSize',16);
you will get: mu=0.24537, sigma=0.213
And if you still want to fit to pdf, just change the function 'normcdf' in 'fun' (and 'y') to 'normpdf'.

how to sort multidimensional matrices along multiple columns

I have a tricky matrix manipulation issue that I could really use some help with.
I need to reorganize a series of 2d matrices so that they align most effectively across subjects. Each matrix has ~50 rows (which are the observations) and 13 columns (which designate the 'weight' of each observation on a series of 13 outcome measures). Based on the manner in which the data are created, there is no inherent meaning in the order of the rows, however I need to reorganize each matrix such that the rows contain meaning between subjects.
Specifically, I want to be able to reorder the matrices such that the specific pattern of weightings in a given row aligns with a similar pattern in the same row across a group of 20 subjects. To make matters worse, some subjects have missing rows, although all have between 45 and 50 rows.
As an example:
subject 1:
[ 0.1, 0.1, 0.2, 0.2, 0.3, 0.3, 0.4, 0.4, 0.5, 0.5, 0.6, 0.6, 0.7;
0.9, 0.8, 0.8, 0.7, 0.7, 0.6, 0.6, 0.5, 0.5, 0.4, 0.4, 0.3, 0.3]
subject 2:
[ 0.8, 0.7, 0.7, 0.6, 0.6, 0.5, 0.5, 0.4, 0.4, 0.3, 0.3, 0.2, 0.2;
0.0, 0.0, 0.1, 0.1, 0.2, 0.2, 0.3, 0.3, 0.4, 0.4, 0.5, 0.6, 0.7]
problem: row 1 in subject 1 aligns best with row 2 in subject 2 (and v.v.) and I would like to reorganize them as such [note: the real life problem is much more convoluted than this].
I apologize ahead of time for how idiosyncratic this issue is, but I really appreciate any help that anyone can give.
Mac

Set axis values range for surf function in Matlab

I'm plotting a surface in matlab, where the x and y values are 0.15-0.85, with 0.05 gaps (0.15,0.2,0.25...).
However, when I plot the surface, the axis are on a 0.0 - 1.0 range, with 0.1 jumps (0.0, 0.1, 0.2...) so the entire surface is distorted. How do I set the axis ranges and deltas?
So as written in my comments you could solve your problem like this:
figure(1)
surf(data)
axis([0.15 0.85 0.15 0.85])
set(gca, 'XTick',0.20:0.05:0.80)
set(gca, 'YTick',0.20:0.05:0.80)

matlab ticks with certain labels

I have the following part:
set(gca,'ylim',[0 0.3],'ytick',0:0.05:0.3);
set(gca,'xlim',[0 1],'xtick',0:0.05:1);
Ticks must remain as they are since when I enable the grid, ticks give me the grid resolution I want. What I also want is that I want to change the labels of x and y.
I want MATLAB to show all ticks but only show the following ticks' label:
0, 0.2, 0.4, 0.8, 1.0 for x
0, 0.1, 0.2, 0.3 for y
Is there a way to do this?
You can assign labels to ticks using a cell array of strings, where each string corresponds to a tick. For ticks at which you don't want any label, use the empty string:
set(gca,'xticklabel',{'0','','','','0.2','','','','0.4','','','','0.6','','','','0.8','','','','1'})
set(gca,'yticklabel',{'0','','0.1','','0.2','','0.3'})