MATLAB: How to mirror the Y axis from -x to x

flipmirrorsymmetric

Hello, I have a data file (xy.txt data) and I imported this data to fit in my matlab, I need to fit a gaussian curve centered at x =0 . However, my data is not symmetric and I need symmetrize that. My x negative side is fine but my positive side is not good. So, I want to cut my data until x = 0 (-20, 0) and mirror this data to x positive axis (0, 20). How should I proceeder?

Best Answer

With only a description, I can only guess. However, assuming that your data are row vectors, something like this will work:
x = -20:20; % Create Data

y = exp(-(x.^2)/11) + rand(1,size(x(x>0),1)); % Create Data
y = y + [zeros(1,size(x(x<=0),2)) 0.5*rand(1,size(x(x>0),2))];
x_full = [x(x<=0), -fliplr(x(x<0))]; % Define & Flip X-Values For ‘(x<=0)’

y_full = [y(x<=0), fliplr(y(x<0))]; % Define & Flip Y-Values For ‘(x<=0)’

figure(1)
plot(x_full, y_full) % Plot Result
grid
If they are column vectors, use flipud instead of fliplr, and replace the commas with semicolons:
x_full = [x(x<=0); -flipud(x(x<0))]; % Define & Flip X-Values For ‘(x<=0)’
y_full = [y(x<=0); flipud(y(x<0))]; % Define & Flip Y-Values For ‘(x<=0)’