How do i display all the date in x axes - matlab

I am using Matlab to plot a graph but i am not getting all the date's in x axes. for example first date starts off 21/2/2013 next date continues as 21/2/2012 but it should be 21/2/2013, 24/2/2013 etc... is there a way to accomplish this? This is the syntax i am using for plotting my graph:
plot(dates,mean([h,l],2),'--r','LineWidth',2)
I am using date as an array, i found out that i can use Units but it does not work
Also is there any way i can add a graph side by side so first graph should appear on right side where the second graph should appear on left hand side. Is this to do with GUI or do i am have to position these graph specifically in a greed

there is a function for that
see
http://www.mathworks.com/help/finance/dateaxis.html
also make sure that the "dates" variable, holds the dates not strings (e.g. 744564)

You want to set the tick marks to something custom I believe. Assuming tickDates has all of the date values where you want a tick value:
plot(dates,mean([h,l],2),'--r','LineWidth',2)
set(gca,'XTicks',tickDates)
As far as side by side plotting, you want to use subplots.
subplot(2,1,1)
plot(dates,mean([h,l],2),'--r','LineWidth',2)
subplot(2,1,2)
For more, see http://www.mathworks.com/help/matlab/creating_plots/setting-axis-parameters.html

Related

MATLAB Data Cursor won't click on every point of plot (R2018b)

I need to get the plot values in between those two points, but when I click with the data cursor in between, the label appears either left or right, as if the cursor only picks up points on a fixed grid.
Is there a way to increase this precision so I can click and get the values in between?
Found the solution:
In the code, this needs to be set after the plot:
dcmObj = datacursormode;
set(dcmObj,'SnapToDataVertex','off')

Matlab date help on x-axis

I have a porkchop plot that looks similar to this:
The contour function used to make it has input arguments for the x and y positions that are serial dates (as that seemed to be required by MATLAB). Then I used the following command to get the format I want:
datetick('x', 2); datetick('y', 2);
The problem I am having is that when I zoom in on the plot the tick labels to not autogenerate and I can be left with no ticks on the x or y axis if I zoom in to use a weeks' date range for example.
I tried enabling 'auto' for XtickMode and YtickMode but when I zoom in or pan after using those commands the relationship between the independent and dependent variables are lost for some reason (aka the dates don't stay with data like they do when you just have numbers on the x axis and zoom in).
Any ideas on how to solve this issue to get the functionality I'm looking for?
I have also tried the command xtickformat('dd-MMM-yy') but I get an error "Invalid numeric tick label format." when I use it with the contour plot.
As far as I know there is no builtin method in MATLAB to do this. I use the datetickzoom function from the MATLAB FileExchange. If you replace all instances of datetick with datetickzoom, it will automatically update the relevant axis labels when you zoom in.

Unable to add Trend Line in Tableau even though both axes are numeric

As shown in the screenshot: both axes are numeric. So why can not the trend line be calculated?
The problem with this set up is that the values on the x-axis are discrete values rather than a measure.
Tableau treats every number as a separate category rather than a point on an axis.
If you click on that field and chose "Convert to measure", you should get an actual scatterplot and you should then be able to add a reference line for each axis.

How to combine different figures in a Matlab script?

I am workin on a some sort of System test wherein i have a set of readings in the form of a .mat file.
It has a structure in the .mat file with one field as Measurement. It has several Arrays(e.g air mass flow, velocity, carbon content) which further have fields like time and value.
From these, I Need to plot the velocity and the air mass flow against time. For that i wrote the following command which gave me the corresponding plots:
plot(Measurement.(Measurement.air_mass_flow.time),Measurement.air_mass_flow.value)
plot(Measurement.(Measurement.velocity.time),Measurement.velocity.value)
Now i Need to create a script in matlab wherein i can get both the curves one under the other i.e. on the same page. Can anyone help in the Approach i should procede with ?
ok now i will further extend my question.
I have two fields as velocity and acceleration. I Need to plot it on the same curve with grids on for the comparison. But the y axis for both are different.
the velocity y-axis is: (0:20:120), which should be displayed on the left side and the acceleration y-axis is: (0:2:12) which should be displayed on the right side.
i wrote the following code for this:
plot(Measurement.(Measurement.VehV_v.time),Measurement.VehV_v.value)
grid on
set(gca,'xtick',[0:500:2000])
set(gca,'ytick',[0:20:120])
hold on
plot(Measurement.(Measurement.accel_w.time),Measurement.accel_w.value)
grid on
set(gca,'xtick',[0:500:2000])
set(gca,'ytick',[0:2:12])
Do i Need to write a function for that as i am directly reading the values from the structure.
plotyy() also doesnt seem to work
But the axis are not matching and the graph for acceleration is very small. Could anyone help me out with this ?
I also want to add a Picture of the Graphs here but unfortunately there is some error here. I hope the question is clear without the Picture.
Yes you can use the subplot command, e.g.:
figure
subplot(1,2,1)
plot(Measurement(Measurement.air_mass_flow.time),Measurement.air_mass_flow.value)
subplot(1,2,2)
plot(Measurement.(Measurement.velocity.time),Measurement.velocity.value)
You can use help subplot on Matlab for further details or have a look at this:
https://www.dartmouth.edu/~rc/classes/matlab_graphics/Matlab-subplots.html

MATLAB: Plotting two different axes on one figure

The MATLAB surf plot below is essentially two plots plotted adjacent to each other. For clarity, I have included some code below used to prepare the plot:
band1 = horzcat(band1, eSurface2(:,:,1));
band2 = horzcat(band2, eSurface2(:,:,2));
surf(band2,'DisplayName','band2');
surf(band3,'DisplayName','band2');
I would like for the y axis numbering to restart at the start of the second graph. How do I go about doing that?
You can use the 'YTick' and 'YTickLabel' properties of the axis to control the ticks, this way you can make it start from zero for the second graph. It will require some trail and error to get it right. See the relevant doc here (you'll have to scroll all the way to the bottom of the page).
Take advantage of the following feature of 'YTickLabel': "If you do not specify enough text labels for all the tick marks, MATLAB uses all of the labels specified, then reuses the specified labels".