Azzera filtri
Azzera filtri

How to mirror a function vertically?

1 visualizzazione (ultimi 30 giorni)
Mohsen
Mohsen il 9 Apr 2014
Risposto: Mohsen il 9 Apr 2014
I have a function with non equal step size in the x axis. How can I mirror it vertically?
Here is my code:
close all; clear all; clc;
depth=[ 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.6 1.8 2 2.2 2.4 2.6 2.7 2.8 2.9 3 3.2 3.3 3.4 3.5 3.6 3.7 3.8 4 4.2 4.4 4.6 4.8 4.9 5 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6 6.2 6.3 6.4 6.5 6.6 6.8 6.9 7 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 8 8.2 8.4 8.6 8.8 9 9.2 9.4 9.6 9.8 10 10.2 10.4 10.6 10.8 11 11.2 11.4 11.6 11.8 12 12.2 12.4 12.6 12.8 13 13.2 13.4 13.6 13.8 14 14.2 14.4 14.6 14.8 15 15.2 15.4 15.6 15.8 16 16.2 16.4 16.6 16.8 17 17.2 17.4 17.6 17.8 18 18.2 18.4 18.6 18.8 19 19.2 19.4 19.6 19.8 20 20.2 20.4 20.6 20.8 21 21.2 21.4 21.6 21.8 22 22.2 22.4 22.6 22.8 23 23.2 23.4 23.6 23.8 24 24.2 24.4 24.6 24.8 25 25.2 25.4 25.6 25.8 26 26.2 26.4 26.6 26.8 27 27.2 27.4 27.6 27.8 28 28.2 28.4 28.6 28.8 29 29.2 29.4 29.6 29.8 30]; rel_dose=[ 61.8 63.2 66 73.8 81.3 86.4 90.5 93.9 96 97.4 98.6 99.2 99.9 99.8 100.7 100 99.2 98.9 98 97.2 96.3 96.1 95.7 95.2 94.7 94.1 93.8 92.8 92.4 92.2 91.7 91.1 90.2 89.6 88.9 88.1 87.2 87.1 86 85.3 85 84.4 84 83.8 83.4 83 82.5 82.1 81.3 81.1 80.3 80.4 79.7 78.7 78.7 77.9 78 77.3 77.2 76.4 76.3 75.6 75.2 74.8 74.1 73.2 72.4 71.9 71.1 70.4 69.7 68.9 68 67.4 66.6 65.9 65.3 64.6 64 63.1 62.4 61.9 61.3 60.5 59.6 59.2 58.5 58 57.4 56.7 56.1 55.5 54.7 54.1 53.8 53 52.4 51.6 51.2 50.8 50.1 49.5 49 48.3 47.8 47.6 46.8 46.3 45.8 45.5 45.1 44.4 43.8 43.5 42.9 42.5 42 41.4 41 40.4 40.3 39.8 39.3 38.9 38.4 38 37.5 37.1 36.6 36.3 35.9 35.4 35.1 34.9 34.4 34.1 33.8 33.4 33 32.6 32.2 31.9 31.5 31.1 30.8 30.4 30.1 29.7 29.5 29.2 28.8 28.4 28.2 27.9 27.5 27.2 26.9 26.6 26.4 25.9 25.9 25.5 25.3 25.1 24.7 24.5 24.2 23.9 23.7 23.3 23.1 22.9 22.7 22.4 22.2];
Seperatio_pt = find(depth==10); depth=depth(1:Seperatio_pt);
rel_dose_1=rel_dose(1:Seperatio_pt); rel_dose_2=rel_dose_1(length(rel_dose_1):-1:1)
figure; plot(depth,rel_dose_1, 'r', 'linewidth', 3);
xlabel('Depth (cm)'); ylabel('Relative Dose (%)'); title('(Normalized Relative Dose as a Function of Depth for a 6 MV POP; FS=10x10 cm2; separation=10 cm'); hold on
plot(depth,rel_dose_2, 'b', 'linewidth', 3);
  1 Commento
Mohsen
Mohsen il 9 Apr 2014
If you run the code, you will see the 2 curves rel_dose_1 and rel_dose_2. Basically, rel_dose_2 should be an inverted version of rel_dose_1 with respect to the midpoint of rel_dose_1. I used the following code to do this:
rel_dose_2=rel_dose_1(length(rel_dose_1):-1:1);
Then, I plotted both as a function of x (depth). This would have worked very well if the step size in the x-axis was constant. However, since that is not the case, the rel_dose_2 is not a perfect mirrored version of the rel_dose_1. I think I have to create a for loop to do this correctly...

Accedi per commentare.

Risposta accettata

Mohsen
Mohsen il 9 Apr 2014
close all; clear all; clc;
depth=[ 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.6 1.8 2 2.2 2.4 2.6 2.7 2.8 2.9 3 3.2 3.3 3.4 3.5 3.6 3.7 3.8 4 4.2 4.4 4.6 4.8 4.9 5 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6 6.2 6.3 6.4 6.5 6.6 6.8 6.9 7 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 8 8.2 8.4 8.6 8.8 9 9.2 9.4 9.6 9.8 10 10.2 10.4 10.6 10.8 11 11.2 11.4 11.6 11.8 12 12.2 12.4 12.6 12.8 13 13.2 13.4 13.6 13.8 14 14.2 14.4 14.6 14.8 15 15.2 15.4 15.6 15.8 16 16.2 16.4 16.6 16.8 17 17.2 17.4 17.6 17.8 18 18.2 18.4 18.6 18.8 19 19.2 19.4 19.6 19.8 20 20.2 20.4 20.6 20.8 21 21.2 21.4 21.6 21.8 22 22.2 22.4 22.6 22.8 23 23.2 23.4 23.6 23.8 24 24.2 24.4 24.6 24.8 25 25.2 25.4 25.6 25.8 26 26.2 26.4 26.6 26.8 27 27.2 27.4 27.6 27.8 28 28.2 28.4 28.6 28.8 29 29.2 29.4 29.6 29.8 30]; rel_dose=[ 61.8 63.2 66 73.8 81.3 86.4 90.5 93.9 96 97.4 98.6 99.2 99.9 99.8 100.7 100 99.2 98.9 98 97.2 96.3 96.1 95.7 95.2 94.7 94.1 93.8 92.8 92.4 92.2 91.7 91.1 90.2 89.6 88.9 88.1 87.2 87.1 86 85.3 85 84.4 84 83.8 83.4 83 82.5 82.1 81.3 81.1 80.3 80.4 79.7 78.7 78.7 77.9 78 77.3 77.2 76.4 76.3 75.6 75.2 74.8 74.1 73.2 72.4 71.9 71.1 70.4 69.7 68.9 68 67.4 66.6 65.9 65.3 64.6 64 63.1 62.4 61.9 61.3 60.5 59.6 59.2 58.5 58 57.4 56.7 56.1 55.5 54.7 54.1 53.8 53 52.4 51.6 51.2 50.8 50.1 49.5 49 48.3 47.8 47.6 46.8 46.3 45.8 45.5 45.1 44.4 43.8 43.5 42.9 42.5 42 41.4 41 40.4 40.3 39.8 39.3 38.9 38.4 38 37.5 37.1 36.6 36.3 35.9 35.4 35.1 34.9 34.4 34.1 33.8 33.4 33 32.6 32.2 31.9 31.5 31.1 30.8 30.4 30.1 29.7 29.5 29.2 28.8 28.4 28.2 27.9 27.5 27.2 26.9 26.6 26.4 25.9 25.9 25.5 25.3 25.1 24.7 24.5 24.2 23.9 23.7 23.3 23.1 22.9 22.7 22.4 22.2];
Seperation_pt = find(depth==10); depth_1=depth(1:Seperation_pt); depth_2=zeros(1,length(depth_1)); depth_2(1)=depth_1(length(depth_1));
for i = 2:length(depth_1) increment=depth_1(i)-depth_1(i-1); depth_2(i)=depth_2(i-1)-increment; end
rel_dose_1=rel_dose(1:Seperation_pt);
figure; plot(depth_1,rel_dose_1, 'r', 'linewidth', 3);
xlabel('Depth (cm)'); ylabel('Relative Dose (%)'); title('(Normalized Relative Dose as a Function of Depth for a 6 MV POP; FS=10x10 cm2; separation=10 cm'); hold on
plot(depth_2,rel_dose_1, 'b', 'linewidth', 3);

Più risposte (0)

Categorie

Scopri di più su Graphics Object Programming in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by