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

38 views (last 30 days)
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]);

Answers (2)

Walter Roberson
Walter Roberson on 19 Jan 2022
Pass the coordinates of the independent axes to plot() before the dependent coordinates -- plot(x,y)
  4 Comments
BP
BP on 24 Jan 2022
I don't understand how this will help with the issue I am having. Please explane using the following details.
There are thousands of csv files I am using Matlab to preform post calculations and plot the csv data. Multiple scopes were used to capture the csv data so the trigger points (t=0) on the x axis are not consistent. I need to process some of this data together in one plot. 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. I don't care about the data before t=0. The t=0 (time) axis trigger point can be the point where the signal goes above 1 db (amplitude) on the y axis of each csv file. I need the plots to look like the scoped were trigg at the same time from the same scope.
I need to fix this issue and also be able to apply the fix to other types of csv data plots as well.
Thank you for your help.
Walter Roberson
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 ?

Sign in to comment.


BP
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,
  3 Comments
BP
BP on 26 Jan 2022
Thank you for your help.
Please explain how these commands should work so I will better understand and troubleshoot issues and errors if needed.
Thanks
Walter Roberson
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.

Sign in to comment.

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!