Is it possible to plot two errorbars on one figure? - matlab

I need to plot two data vectors with errorbars on one figure. errorbar() function does it, but only for one data set. Is there a way to plot second graph on the same figure?

Been an idiot, forgive me. I just needed to pass in a two-dimensional matrices instead of vectors.

Related

Arraging multiple 3D plots

I have created 6 3D plots that I need to include in a research paper. However, I need to all the plots in a grid.
I've been trying the function subplot but all my plots are combining instead of forming a grid. I have tried setting nrows to various numbers but it does not change the layout. Any ideas on how to fix this? Or other functions that may serve the same purpose?
Shows the function for 1/6 plots, then the subplot function. to the right is the output:

MATLAB: Digitizing a plot with multiple variables and implementing the data

I have 8 plots which I want to implement in my Matlab code. These plots originate from several research papers, hence, I need to digitize them first in order to be able to use them.
An example of a plot is shown below:
This is basically a surface plot with three different variables. I know how to digitize a regular plot with just X and Y coordinates. However, how would one digitize a graph like this? I am quite unsure, hence, the question.
Also, If I would be able to obtain the data from this plot. How would you be able to utilize it in your code? Maybe with some interpolation and extrapolation between the given data points?
Any tips regarding this topic are welcome.
Thanks in advance
Here is what I would suggest:
Read the image in Matlab using imread.
Manually find the pixel position of the left bottom corner and the upper right corner
Using these pixels values and the real numerical value, it is simple to determine the x and y value of every pixel. I suggest you use meshgrid.
Knowing that the curves are in black, then remove every non-black pixel from the image, which leaves you only with the curves and the numbers.
Then use the function bwareaopen to remove the small objects (the numbers). Don't forget to invert the image to remove the black instead of the white.
Finally, by using point #3 and the result of point #6, you can manually extract the data of the graph. It won't be easy, but it will be feasible.
You will need the data for the three variables in order to create a plot in Matlab, which you can get either from the previous research or by estimating and interpolating values from the plot. Once you get the data though, there are two functions that you can use to make surface plots, surface and surf, surf is pretty much the same as surface but includes shading.
For interpolation and extrapolation it sounds like you might want to check out 2D interpolation, interp2. The interp2 function can also do extrapolation as well.
You should read the documentation for these functions and then post back with specific problems if you have any.

In MATLAB, how can I combine 2 different `histc` results into one, and produce a 3D plot?

In one histc, I have latitude data. In another histc, I have longitude data. I have plotted the bar graphs of these 2 separately. Now, I want to combine them and produce a 3D graph where the x-axis is latitude, y-axis is longitude, and z-axis is the frequency with which each latitude-longitude pair occurs.
The problem is that, while plotting the graphs for latitudes and longitudes separately, I calculated their respective frequencies by taking their individual histcs separately. However, when I want to make it a 3D plot, I can't seem to find a way to take the histc of the latitude-longitude pairs.
EDIT: I am adding my code for plotting the bar graphs here upon being asked by one commenter to do so, though I don't see how that would help. The bar graph for latitude is: bar(unique(M), histc(M,unique(M))) and that for longitude is bar(unique(N), histc(N,unique(N))). And the M and N are nx1 matrices. (Actually, they are 2 columns of a much larger matrix. But for simplicity in comprehension, I have avoided writing complex formulae here.)
EDIT: I reckon what I am looking for might be solved by surface plot, surf. But I am not sure. If it is, then the issue I am facing, speaking in terms of surf, can be stated as an issue in defining the Z parameter.
latitudes=180*(rand(1,10000)-0.5);
longitudes=360*(rand(1,10000)-0.5);
d=[latitudes;longitudes];
minVal_Lat=-90;
maxVal_Lat=90;
minVal_Long=-180;
maxVal_Long=180;
delta=10;
axisLat=minVal_Lat:delta:maxVal_Lat;
axisLong=minVal_Long:delta:maxVal_Long;
nPDF_Lat=length(axisLat);
nPDF_Long=length(axisLong);
PDF=zeros(nPDF_Lat,nPDF_Long);
temp=0;
count_i=1;
count_j=1;
for i=axisLat;
lowlimit_x=i-delta/2;
upperlimit_x =i+delta/2;
for j=axisLong;
lowlimit_y=j-delta/2;
upperlimit_y =j+delta/2;
temp=0;
for k=1:length(d(1,:));
if lowlimit_x<=d(1,k) & d(1,k)<upperlimit_x
if lowlimit_y<=d(2,k) & d(2,k)<upperlimit_y
temp=temp+1;
else
end
else
end
end
PDF(count_i,count_j)=temp;
count_j=count_j+1;
end
count_i=count_i+1;
count_j=1;
end
normFactor=sum(sum(PDF));
PDF=(1/normFactor)*PDF;
randVar_Lat=minVal_Lat:delta:maxVal_Lat;
randVar_Long=minVal_Long:delta:maxVal_Long;
surf(randVar_Lat,randVar_Long,PDF')
If you want get a 2D probability density function with surf plot, these codes will be worked.

How to plot a zero-one matrix that will look like scatter?

I have a matrix of zeros and ones and I want to plot the ones in their location in the matrix. So that it will look like the matrix but instead of ones a marker and instead of zeros nothing.
Is there a function for doing this or I need to get the x and y for every one and then just do a simple scatter plot?
Thank you for the help!
Try the function spy, it plots a blue dot for every non-zero entry of a matrix.
imagesc
is an approach for this that I find useful.
Another option is to get coordinates of non-zero elements with FIND:
[x,y] = find(A);
scatter(x,y)
It's the same way as used by SPY, just with a little more control. In opposite to PLOT or SCATTER, SPY does not return points handle, which anyway can be retrieved by FINDOBJ.

How to make a log plot in matlab

Is it possible to make a plot in matlab that does not actually take the logs of the values? I'm plotting wide ranges of values and when I try to make a log plot of them, those below 1 become negative. I would just like it to plot the values on a log scale without taking their logs.
Alternatively, set(gca,'XScale','log') if you have your plot already.
Yes, it is possible. Use the loglog command.
The example from the Mathworks website:
x = logspace(-1,2); % generate a sequence of points equally spaced logarithmically
loglog(x,exp(x),'-s')
grid on
If you do not want both axes to be log scale, use semilogx or semilogy.
So, you want to plot liner data on logarithmic axes? You can exponentiate you values before using the log plot. This way the point p=(10,3) will plot at the x=10 position.