Fixing MATLAB's X-Axis: Troubleshooting Data Subtraction Issues | Learn How Here

  • MATLAB
  • Thread starter Jason Chiu
  • Start date
  • Tags
    Matlab
In summary, the code provided shows a method for subtracting data points from two tables and creating a plot of the resulting values. However, the x-axis range is automatically set to 0 to 1400 in steps of 200, when it should be from 0 to 0.07 in steps of 0.01. To fix this, the option "PlotRange" can be added when calling ListPlot to specify the desired x-value range.
  • #1
Jason Chiu
1
0
I have a table of data points to be subtracted by another table of data points. I have succeed in subtracting the y values of each data point successfully, but it is the x values of each data point in that I have trouble.

m =10;
SubDataList=Table[{DataList[[i,All,2]]-BGData[[All,2]]},{i,1,m}];
Do[{SubDataPlot=ListPlot[SubDataList[]];},{i,1,m}]This is the code that I am having trouble with. However, my plot will get y values correct, but my x-axis is automatically set to 0 to 1400 in steps of 200. However, my data points shows that my x-axis should be from 0 to 0.07 in steps of 0.01.

Both "DataList" and "BGData" are table of its own and the specifications that I have done for each just extracts the y-values in each table and subtracts them.
 
Physics news on Phys.org
  • #2
What can I do in order to fix my data plot so that my x-axis is from 0 to 0.07 in steps of 0.01?You can specify the x-value range when calling ListPlot by adding the option PlotRange -> {xmin, xmax}. For example,m = 10;SubDataList=Table[{DataList[[i,All,2]]-BGData[[All,2]]},{i,1,m}];Do[{SubDataPlot=ListPlot[SubDataList[], PlotRange -> {0, 0.07}];},{i,1,m}]
 

1. Why is my x-axis not showing the correct data on my MATLAB plot?

There could be several reasons for this issue. One common reason is that the data on your x-axis is not in the correct format. Make sure that your data is in numerical format and not in string format. Another reason could be that your data is not within the range of the axis limits. Adjust the axis limits to ensure that all of your data is visible on the plot.

2. How can I change the labels on my x-axis in MATLAB?

To change the labels on your x-axis, you can use the xticklabels function. This function allows you to specify the labels you want to use for each tick on the x-axis. You can also use the xlabel function to add a label to the x-axis.

3. How do I change the scale of my x-axis in MATLAB?

To change the scale of your x-axis, you can use the xscale function. This function allows you to specify the type of scale you want to use, such as linear, logarithmic, or symlog. You can also use the xlim function to manually set the limits of the x-axis.

4. Why does my x-axis have too many or too few ticks?

The number of ticks on your x-axis is determined by MATLAB based on the axis limits and the size of your plot. If you want to adjust the number of ticks, you can use the xticks function to manually specify the locations of the ticks, or use the xtickformat function to specify a specific format for the ticks.

5. How do I remove the x-axis entirely from my MATLAB plot?

To remove the x-axis from your plot, you can use the box off command. This will remove the entire axis, including the ticks and labels. If you only want to remove the ticks and labels, you can use the xticklabels function to set the labels to an empty string, and use the xtick function to remove the ticks.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
851
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
986
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
553
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
6K
Back
Top