# How to shifting or move the time axis to the left in a MATLAB plot.

15 views (last 30 days)
BP on 19 Jan 2022
Commented: Walter Roberson on 26 Jan 2022
I have a matlab plot with two signals. The time axis is slightly different on one. How can I shift or move the time axis on the one to the left in my MATLAB plot.
I have tried using "plot(xArray + amountToShift, yArray);". The fourth line in the code below becomed "plot(sum+3)". This will only move the signal vertically up and down on the plot? I need to move the signal right and left on the plot.
Below is code for the plot.
sum = A{:,5} + B{:,5} + C{:,5};% Only use colume 5 of the csv files
hold all
figure('DefaultAxesFontSize',10)%Plot font size
plot(sum);
hold all
plot(D{:,5});
hold all
grid on;
xlabel('Time (\mus)')
ylabel('Amplitude (db)')
%xlim([-4.52e-7 5.52e-6]);
%ylim([0 9]);

Walter Roberson on 19 Jan 2022
Pass the coordinates of the independent axes to plot() before the dependent coordinates -- plot(x,y)
Walter Roberson on 24 Jan 2022
Your original question contained none of that information !!!
Do your files have a column which is relative time? Or is there a fixed frequency that applies to all of them, such that we can calculate relative time as (difference in index) divided by (frequency) ?
If your files contain multiple columns, are there multiple data columns? If so then should each one be aligned independently?
Are your data columns directly in dB, or is there a fixed multiplier to convert to dB, or does the dB need to be calculated from the power spectrum somehow ?

BP on 25 Jan 2022
Each csv spreadsheet consist of five columns. The first three columns are general information (location, date and time).
Column four is the time in seconds. Column five is amplitude. The plots waveforms are generated from column four (time in seconds) and column five (amplitue in db). It is a time (on the x axis) vs. amplitude (on the Y axis) plot using columns four and five of two csv spreadsheets generated by two seperate data recorders.
There is no set frequency.
Data colume four of each spreadsheet is just a number related to time in seconds.
Data colume five of each spreadsheet is just a number which relates to the sound amplitude in db.
Both are just a numbers in the two spreadsheets columns four and five.
After doing a readtable to get the data into MATLAB, My code does certain calculations and generates a combined plot from the two spreadsheets columns four and five.
I need a way to have matlab find the t=0 point on the x axis of each csv file and plot the data together begaining at T=0.
Thanks,
Walter Roberson on 26 Jan 2022
There isn't much to it. Replace T with the name of your table. Replace "Amplitude" with the name of the table variable that holds the amplitudes. Replace "Seconds" with the name of the table variable that holds the seconds.
find(condition, 1) returns the first index where the condition is true.

R2021a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!