Trouble with Interp2

35 vues (au cours des 30 derniers jours)
Peter Cheimets
Peter Cheimets le 24 Déc 2025 à 15:54
Commenté : Paul il y a environ 23 heures
I am trying to use interp2 to look up values on in a table. I think that the problem is posed correctly (though obviously it is not), but all I get back is that the:
Error using interp2>makegriddedinterp (line 230)
Input grid is not a valid MESHGRID.
Error in interp2 (line 134)
F = makegriddedinterp(X, Y, V, method,extrap);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in LYNX_reflectivity_test_2 (line 61)
interp2(ang_mesh,ener_mesh,Refl,1,1000)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The code is below. The first step is to create a table of reflectivies as a function of angle and energy, interpolate that table line by line to create a finer grid in energy, and then test that the meshgrid works. That is where is fails, and I just can't see what the problem is with the 2 interp2 statements at the bottom.
Thanks
Peter
Code below:
%Ir 10.nm/Cr 10.nm/SiO2 at 300.eV, P=0. Ir 10.nm/Cr 10.nm/SiO2 at 1000.eV, P=0. Ir 10.nm/Cr 10.nm/SiO2 at 5000.eV, P=0. Ir 10.nm/Cr 10.nm/SiO2 at 10000.eV, P=0.
%Angle (deg), Reflectivity, Transmission into substrate Angle (deg), Reflectivity, Transmission into substrate Angle (deg), Reflectivity, Transmission into substrate Angle (deg), Reflectivity, Transmission into substrate
Ir_10nm_Cr_10nm= [...
0.000000 1.00000 0.000000 0.000000 1.00000 0.000000 0.000000 1.00000 0.000000 0.000000 1.00000 0.000000
0.100000 0.982382 8.652573E-07 0.100000 0.980819 2.761637E-08 0.100000 0.961194 7.556862E-09 0.100000 0.970851 7.765713E-09
0.200000 0.965071 1.719669E-06 0.200000 0.961976 5.596694E-08 0.200000 0.922734 2.765021E-08 0.200000 0.938211 1.647113E-05
0.300000 0.948057 2.567899E-06 0.300000 0.943431 8.642812E-08 0.300000 0.883305 1.645055E-07 0.300000 0.892460 6.416535E-04
0.400000 0.931332 3.414433E-06 0.400000 0.925152 1.205377E-07 0.400000 0.841437 1.641682E-05 0.400000 0.776047 3.014587E-02
0.500000 0.914888 4.263738E-06 0.500000 0.907106 1.602024E-07 0.500000 0.795022 1.044327E-04 0.500000 0.414675 0.203665
0.600000 0.898715 5.120294E-06 0.600000 0.889262 2.079145E-07 0.600000 0.740373 6.502263E-04 0.600000 2.639916E-02 0.600880
0.700000 0.882807 5.988663E-06 0.700000 0.871589 2.670899E-07 0.700000 0.670460 4.532680E-03 0.700000 5.090132E-02 0.666863
0.800000 0.867156 6.873516E-06 0.800000 0.854059 3.426060E-07 0.800000 0.582072 1.752900E-02 0.800000 8.964668E-03 0.739812
0.900000 0.851754 7.779961E-06 0.900000 0.836637 4.418530E-07 0.900000 0.462636 3.669631E-02 0.900000 6.255109E-03 0.778701
1.00000 0.836595 8.712494E-06 1.00000 0.819307 5.757112E-07 1.00000 0.287212 8.603266E-02 1.00000 8.307789E-03 0.801262
1.10000 0.821673 9.676867E-06 1.10000 0.802032 7.623986E-07 1.10000 0.113086 0.191545 1.10000 3.204778E-03 0.823322
1.20000 0.806979 1.067877E-05 1.20000 0.784783 1.032557E-06 1.20000 4.265893E-02 0.302449 1.20000 1.369765E-03 0.841015
1.30000 0.792511 1.172367E-05 1.30000 0.767544 1.440837E-06 1.30000 3.424924E-02 0.377434 1.30000 2.013776E-03 0.853180
1.40000 0.778259 1.281891E-05 1.40000 0.750272 2.097700E-06 1.40000 4.541511E-02 0.422315 1.40000 2.044105E-03 0.863582
1.50000 0.764220 1.397090E-05 1.50000 0.732951 3.244685E-06 1.50000 3.447726E-02 0.462093 1.50000 8.998325E-05 0.874569
1.60000 0.750386 1.518820E-05 1.60000 0.715537 5.501835E-06 1.60000 1.121614E-02 0.507514 1.60000 8.285744E-04 0.881952
1.70000 0.736754 1.647850E-05 1.70000 0.698017 1.043718E-05 1.70000 3.812777E-03 0.545209 1.70000 9.592185E-04 0.888774
1.80000 0.723318 1.785118E-05 1.80000 0.680360 1.979164E-05 1.80000 5.419738E-03 0.572716 1.80000 1.404092E-04 0.895597
1.90000 0.710075 1.931691E-05 1.90000 0.662529 3.291488E-05 1.90000 6.503398E-03 0.595698 1.90000 3.395465E-04 0.901000
2.00000 0.697017 2.088734E-05 2.00000 0.644491 4.970375E-05 2.00000 8.737379E-03 0.614274 2.00000 3.610264E-04 0.905901
2.10000 0.684142 2.257595E-05 2.10000 0.626204 7.134984E-05 2.10000 8.188237E-03 0.631155 2.10000 3.175893E-04 0.910347
2.20000 0.671445 2.439662E-05 2.20000 0.607643 9.966306E-05 2.20000 3.437309E-03 0.649587 2.20000 3.847828E-05 0.914674
2.30000 0.658921 2.636680E-05 2.30000 0.588763 1.371713E-04 2.30000 5.906834E-04 0.666898 2.30000 2.018896E-04 0.918212
2.40000 0.646567 2.850380E-05 2.40000 0.569542 1.872420E-04 2.40000 1.199021E-03 0.680769 2.40000 2.279600E-04 0.921553
2.50000 0.634379 3.083119E-05 2.50000 0.549920 2.546647E-04 2.50000 1.850882E-03 0.692946 2.50000 2.762698E-05 0.924826
2.60000 0.622354 3.337174E-05 2.60000 0.529880 3.458717E-04 2.60000 2.201997E-03 0.704161 2.60000 1.045066E-04 0.927638
2.70000 0.610487 3.615420E-05 2.70000 0.509386 4.698597E-04 2.70000 2.767883E-03 0.714045 2.70000 1.058603E-04 0.930281
2.80000 0.598776 3.921089E-05 2.80000 0.488413 6.389660E-04 2.80000 2.139947E-03 0.723734 2.80000 9.618340E-05 0.932737
2.90000 0.587217 4.257846E-05 2.90000 0.466955 8.699156E-04 2.90000 6.292278E-04 0.733747 2.90000 1.226485E-05 0.935114
3.00000 0.575808 4.630103E-05 3.00000 0.445010 1.185337E-03 3.00000 1.415811E-04 0.742847 3.00000 7.197971E-05 0.937195];
angle = [0:.1:3];
energy = [300:970:10000];
[ener_mesh, ang_mesh] = meshgrid(energy,angle);
i = 1;
indexs = [2 5 8 11];
energy_start = [300 1000 5000 10000];
Refl = zeros(length(angle),length(energy));
row_i = zeros(1,length(energy));
%Refl(i,:) = ones(1,length(energy));
for i = 1:1:length(angle)
row_i = row_i*0;
row_i = interp1(energy_start,Ir_10nm_Cr_10nm(i,indexs),energy,"linear");
Refl(i,:) = row_i;
end %end of for
%test above
ang_mesh
ang_mesh = 31×11
0 0 0 0 0 0 0 0 0 0 0 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.4000 0.4000 0.4000 0.4000 0.4000 0.4000 0.4000 0.4000 0.4000 0.4000 0.4000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.6000 0.6000 0.6000 0.6000 0.6000 0.6000 0.6000 0.6000 0.6000 0.6000 0.6000 0.7000 0.7000 0.7000 0.7000 0.7000 0.7000 0.7000 0.7000 0.7000 0.7000 0.7000 0.8000 0.8000 0.8000 0.8000 0.8000 0.8000 0.8000 0.8000 0.8000 0.8000 0.8000 0.9000 0.9000 0.9000 0.9000 0.9000 0.9000 0.9000 0.9000 0.9000 0.9000 0.9000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.1000 1.1000 1.1000 1.1000 1.1000 1.1000 1.1000 1.1000 1.1000 1.1000 1.1000 1.2000 1.2000 1.2000 1.2000 1.2000 1.2000 1.2000 1.2000 1.2000 1.2000 1.2000 1.3000 1.3000 1.3000 1.3000 1.3000 1.3000 1.3000 1.3000 1.3000 1.3000 1.3000 1.4000 1.4000 1.4000 1.4000 1.4000 1.4000 1.4000 1.4000 1.4000 1.4000 1.4000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
ener_mesh
ener_mesh = 31×11
300 1270 2240 3210 4180 5150 6120 7090 8060 9030 10000 300 1270 2240 3210 4180 5150 6120 7090 8060 9030 10000 300 1270 2240 3210 4180 5150 6120 7090 8060 9030 10000 300 1270 2240 3210 4180 5150 6120 7090 8060 9030 10000 300 1270 2240 3210 4180 5150 6120 7090 8060 9030 10000 300 1270 2240 3210 4180 5150 6120 7090 8060 9030 10000 300 1270 2240 3210 4180 5150 6120 7090 8060 9030 10000 300 1270 2240 3210 4180 5150 6120 7090 8060 9030 10000 300 1270 2240 3210 4180 5150 6120 7090 8060 9030 10000 300 1270 2240 3210 4180 5150 6120 7090 8060 9030 10000 300 1270 2240 3210 4180 5150 6120 7090 8060 9030 10000 300 1270 2240 3210 4180 5150 6120 7090 8060 9030 10000 300 1270 2240 3210 4180 5150 6120 7090 8060 9030 10000 300 1270 2240 3210 4180 5150 6120 7090 8060 9030 10000 300 1270 2240 3210 4180 5150 6120 7090 8060 9030 10000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Refl
Refl = 31×11
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.9824 0.9795 0.9747 0.9700 0.9652 0.9615 0.9634 0.9652 0.9671 0.9690 0.9709 0.9651 0.9593 0.9498 0.9403 0.9308 0.9232 0.9262 0.9292 0.9322 0.9352 0.9382 0.9481 0.9394 0.9248 0.9102 0.8956 0.8836 0.8854 0.8871 0.8889 0.8907 0.8925 0.9313 0.9195 0.8992 0.8789 0.8586 0.8395 0.8268 0.8141 0.8014 0.7887 0.7760 0.9149 0.8995 0.8724 0.8452 0.8180 0.7836 0.7098 0.6360 0.5622 0.4885 0.4147 0.8987 0.8792 0.8431 0.8070 0.7709 0.7190 0.5804 0.4419 0.3034 0.1649 0.0264 0.8828 0.8580 0.8092 0.7605 0.7117 0.6519 0.5317 0.4115 0.2913 0.1711 0.0509 0.8672 0.8357 0.7697 0.7038 0.6378 0.5649 0.4537 0.3425 0.2313 0.1201 0.0090 0.8518 0.8114 0.7207 0.6300 0.5393 0.4489 0.3604 0.2719 0.1833 0.0948 0.0063 0.8366 0.7834 0.6544 0.5253 0.3963 0.2788 0.2247 0.1706 0.1165 0.0624 0.0083 0.8217 0.7555 0.5885 0.4214 0.2543 0.1098 0.0885 0.0672 0.0458 0.0245 0.0032 0.8070 0.7347 0.5547 0.3748 0.1948 0.0414 0.0334 0.0254 0.0174 0.0094 0.0014 0.7925 0.7180 0.5402 0.3624 0.1846 0.0333 0.0270 0.0208 0.0145 0.0083 0.0020 0.7783 0.7027 0.5318 0.3608 0.1899 0.0441 0.0357 0.0273 0.0189 0.0105 0.0020
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
interp2(ang_mesh,ener_mesh,Refl,1,1000)
Error using interp2>makegriddedinterp (line 230)
Input grid is not a valid MESHGRID.

Error in interp2 (line 134)
F = makegriddedinterp(X, Y, V, method,extrap);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
interp2(ang_mesh,ener_mesh,Refl,2.6,10000)

Réponse acceptée

Paul
Paul il y a environ 7 heures
Modifié(e) : Paul il y a environ 7 heures
Hi Peter,
I think the arguments to interp2 are backwards, but there are some other considerations
Ir_10nm_Cr_10nm= [...
0.000000 1.00000 0.000000 0.000000 1.00000 0.000000 0.000000 1.00000 0.000000 0.000000 1.00000 0.000000
0.100000 0.982382 8.652573E-07 0.100000 0.980819 2.761637E-08 0.100000 0.961194 7.556862E-09 0.100000 0.970851 7.765713E-09
0.200000 0.965071 1.719669E-06 0.200000 0.961976 5.596694E-08 0.200000 0.922734 2.765021E-08 0.200000 0.938211 1.647113E-05
0.300000 0.948057 2.567899E-06 0.300000 0.943431 8.642812E-08 0.300000 0.883305 1.645055E-07 0.300000 0.892460 6.416535E-04
0.400000 0.931332 3.414433E-06 0.400000 0.925152 1.205377E-07 0.400000 0.841437 1.641682E-05 0.400000 0.776047 3.014587E-02
0.500000 0.914888 4.263738E-06 0.500000 0.907106 1.602024E-07 0.500000 0.795022 1.044327E-04 0.500000 0.414675 0.203665
0.600000 0.898715 5.120294E-06 0.600000 0.889262 2.079145E-07 0.600000 0.740373 6.502263E-04 0.600000 2.639916E-02 0.600880
0.700000 0.882807 5.988663E-06 0.700000 0.871589 2.670899E-07 0.700000 0.670460 4.532680E-03 0.700000 5.090132E-02 0.666863
0.800000 0.867156 6.873516E-06 0.800000 0.854059 3.426060E-07 0.800000 0.582072 1.752900E-02 0.800000 8.964668E-03 0.739812
0.900000 0.851754 7.779961E-06 0.900000 0.836637 4.418530E-07 0.900000 0.462636 3.669631E-02 0.900000 6.255109E-03 0.778701
1.00000 0.836595 8.712494E-06 1.00000 0.819307 5.757112E-07 1.00000 0.287212 8.603266E-02 1.00000 8.307789E-03 0.801262
1.10000 0.821673 9.676867E-06 1.10000 0.802032 7.623986E-07 1.10000 0.113086 0.191545 1.10000 3.204778E-03 0.823322
1.20000 0.806979 1.067877E-05 1.20000 0.784783 1.032557E-06 1.20000 4.265893E-02 0.302449 1.20000 1.369765E-03 0.841015
1.30000 0.792511 1.172367E-05 1.30000 0.767544 1.440837E-06 1.30000 3.424924E-02 0.377434 1.30000 2.013776E-03 0.853180
1.40000 0.778259 1.281891E-05 1.40000 0.750272 2.097700E-06 1.40000 4.541511E-02 0.422315 1.40000 2.044105E-03 0.863582
1.50000 0.764220 1.397090E-05 1.50000 0.732951 3.244685E-06 1.50000 3.447726E-02 0.462093 1.50000 8.998325E-05 0.874569
1.60000 0.750386 1.518820E-05 1.60000 0.715537 5.501835E-06 1.60000 1.121614E-02 0.507514 1.60000 8.285744E-04 0.881952
1.70000 0.736754 1.647850E-05 1.70000 0.698017 1.043718E-05 1.70000 3.812777E-03 0.545209 1.70000 9.592185E-04 0.888774
1.80000 0.723318 1.785118E-05 1.80000 0.680360 1.979164E-05 1.80000 5.419738E-03 0.572716 1.80000 1.404092E-04 0.895597
1.90000 0.710075 1.931691E-05 1.90000 0.662529 3.291488E-05 1.90000 6.503398E-03 0.595698 1.90000 3.395465E-04 0.901000
2.00000 0.697017 2.088734E-05 2.00000 0.644491 4.970375E-05 2.00000 8.737379E-03 0.614274 2.00000 3.610264E-04 0.905901
2.10000 0.684142 2.257595E-05 2.10000 0.626204 7.134984E-05 2.10000 8.188237E-03 0.631155 2.10000 3.175893E-04 0.910347
2.20000 0.671445 2.439662E-05 2.20000 0.607643 9.966306E-05 2.20000 3.437309E-03 0.649587 2.20000 3.847828E-05 0.914674
2.30000 0.658921 2.636680E-05 2.30000 0.588763 1.371713E-04 2.30000 5.906834E-04 0.666898 2.30000 2.018896E-04 0.918212
2.40000 0.646567 2.850380E-05 2.40000 0.569542 1.872420E-04 2.40000 1.199021E-03 0.680769 2.40000 2.279600E-04 0.921553
2.50000 0.634379 3.083119E-05 2.50000 0.549920 2.546647E-04 2.50000 1.850882E-03 0.692946 2.50000 2.762698E-05 0.924826
2.60000 0.622354 3.337174E-05 2.60000 0.529880 3.458717E-04 2.60000 2.201997E-03 0.704161 2.60000 1.045066E-04 0.927638
2.70000 0.610487 3.615420E-05 2.70000 0.509386 4.698597E-04 2.70000 2.767883E-03 0.714045 2.70000 1.058603E-04 0.930281
2.80000 0.598776 3.921089E-05 2.80000 0.488413 6.389660E-04 2.80000 2.139947E-03 0.723734 2.80000 9.618340E-05 0.932737
2.90000 0.587217 4.257846E-05 2.90000 0.466955 8.699156E-04 2.90000 6.292278E-04 0.733747 2.90000 1.226485E-05 0.935114
3.00000 0.575808 4.630103E-05 3.00000 0.445010 1.185337E-03 3.00000 1.415811E-04 0.742847 3.00000 7.197971E-05 0.937195];
The data array Ir_10nm_Cr_10nm has an interesting structure, like columns 1 and 4 and 7 etc. are the same and increasing by 0.1 and are (concidentally?) the same values as the angle vector defined next. Is that correct?
angle = [0:.1:3];
energy = [300:970:10000];
whos Ir* angle energy
Name Size Bytes Class Attributes Ir_10nm_Cr_10nm 31x12 2976 double angle 1x31 248 double energy 1x11 88 double
It seems like the intent is for the the data array to be the function points that correspond to the data points in angle and energy. But the data array has one more column than the energy vector.
[ener_mesh, ang_mesh] = meshgrid(energy,angle);
i = 1;
indexs = [2 5 8 11];
energy_start = [300 1000 5000 10000];
Is energy_start supposed to correspond to the values in energy(indexs)?
energy(indexs)
ans = 1×4
1270 4180 7090 10000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
The expectation is that Refl will corredspond to energy varyging across the columns and angle down the rows consistent with the ener_mesh and ang_mesh definitions in meshgrid format.
Refl = zeros(length(angle),length(energy));
size(Refl)
ans = 1×2
31 11
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
row_i = zeros(1,length(energy));
%Refl(i,:) = ones(1,length(energy));
for i = 1:1:length(angle)
row_i = row_i*0;
row_i = interp1(energy_start,Ir_10nm_Cr_10nm(i,indexs),energy,"linear");
Refl(i,:) = row_i;
end %end of for
size(Refl)
ans = 1×2
31 11
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
%test above
whos ang_mesh ener_mesh Refl
Name Size Bytes Class Attributes Refl 31x11 2728 double ang_mesh 31x11 2728 double ener_mesh 31x11 2728 double
For interp2, the sample points and sample value inputs should be in meshgrid format. The way everything has been defined ener_mesh is the "X" and ang_mesh is the "Y" that correspond to the points in Refl all in meshgrid format. So reverse those two inputs. It looked like the last two inputs were meant to be energy = 1000 and angle = 1, so those should be reversed as well.
%interp2(ang_mesh,ener_mesh,Refl,1,1000)
interp2(ener_mesh,ang_mesh,Refl,1000,1)
ans = 0.7982
Not clear to me if that's the result you're expecting because of questions above regarding structure the data to begin with.
Unless the Ir_10nm_Cr_10nm array is really four groups of three variables, where each group correponds to each element of energy_start and the second column of each group is the actual variable of interest (Refl?). If that's the case, there may be alternative ways to organize the data to make it easier to work with.
interp2(ang_mesh,ener_mesh,Refl,2.6,10000)
Error using interp2>makegriddedinterp (line 230)
Input grid is not a valid MESHGRID.

Error in interp2 (line 134)
F = makegriddedinterp(X, Y, V, method,extrap);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2 commentaires
Peter Cheimets
Peter Cheimets il y a environ 4 heures
This worked as well. Yes, the data is 4 separate runs at different energies with the same set of angles. I think that the take way for me is that the first of the two meshes in the function call needs to be the one that changes column to column.
Thanks everyone.
Peter
Paul
Paul il y a environ 2 heures
"... the data is 4 separate runs ..."
Consider rearranging the data so that each run is contained within a single variable, like a struct. The use a struct array to store all of the runs.
Ir_10nm_Cr_10nm= [...
0.000000 1.00000 0.000000 0.000000 1.00000 0.000000 0.000000 1.00000 0.000000 0.000000 1.00000 0.000000
0.100000 0.982382 8.652573E-07 0.100000 0.980819 2.761637E-08 0.100000 0.961194 7.556862E-09 0.100000 0.970851 7.765713E-09
0.200000 0.965071 1.719669E-06 0.200000 0.961976 5.596694E-08 0.200000 0.922734 2.765021E-08 0.200000 0.938211 1.647113E-05
0.300000 0.948057 2.567899E-06 0.300000 0.943431 8.642812E-08 0.300000 0.883305 1.645055E-07 0.300000 0.892460 6.416535E-04
0.400000 0.931332 3.414433E-06 0.400000 0.925152 1.205377E-07 0.400000 0.841437 1.641682E-05 0.400000 0.776047 3.014587E-02
0.500000 0.914888 4.263738E-06 0.500000 0.907106 1.602024E-07 0.500000 0.795022 1.044327E-04 0.500000 0.414675 0.203665
0.600000 0.898715 5.120294E-06 0.600000 0.889262 2.079145E-07 0.600000 0.740373 6.502263E-04 0.600000 2.639916E-02 0.600880
0.700000 0.882807 5.988663E-06 0.700000 0.871589 2.670899E-07 0.700000 0.670460 4.532680E-03 0.700000 5.090132E-02 0.666863
0.800000 0.867156 6.873516E-06 0.800000 0.854059 3.426060E-07 0.800000 0.582072 1.752900E-02 0.800000 8.964668E-03 0.739812
0.900000 0.851754 7.779961E-06 0.900000 0.836637 4.418530E-07 0.900000 0.462636 3.669631E-02 0.900000 6.255109E-03 0.778701
1.00000 0.836595 8.712494E-06 1.00000 0.819307 5.757112E-07 1.00000 0.287212 8.603266E-02 1.00000 8.307789E-03 0.801262
1.10000 0.821673 9.676867E-06 1.10000 0.802032 7.623986E-07 1.10000 0.113086 0.191545 1.10000 3.204778E-03 0.823322
1.20000 0.806979 1.067877E-05 1.20000 0.784783 1.032557E-06 1.20000 4.265893E-02 0.302449 1.20000 1.369765E-03 0.841015
1.30000 0.792511 1.172367E-05 1.30000 0.767544 1.440837E-06 1.30000 3.424924E-02 0.377434 1.30000 2.013776E-03 0.853180
1.40000 0.778259 1.281891E-05 1.40000 0.750272 2.097700E-06 1.40000 4.541511E-02 0.422315 1.40000 2.044105E-03 0.863582
1.50000 0.764220 1.397090E-05 1.50000 0.732951 3.244685E-06 1.50000 3.447726E-02 0.462093 1.50000 8.998325E-05 0.874569
1.60000 0.750386 1.518820E-05 1.60000 0.715537 5.501835E-06 1.60000 1.121614E-02 0.507514 1.60000 8.285744E-04 0.881952
1.70000 0.736754 1.647850E-05 1.70000 0.698017 1.043718E-05 1.70000 3.812777E-03 0.545209 1.70000 9.592185E-04 0.888774
1.80000 0.723318 1.785118E-05 1.80000 0.680360 1.979164E-05 1.80000 5.419738E-03 0.572716 1.80000 1.404092E-04 0.895597
1.90000 0.710075 1.931691E-05 1.90000 0.662529 3.291488E-05 1.90000 6.503398E-03 0.595698 1.90000 3.395465E-04 0.901000
2.00000 0.697017 2.088734E-05 2.00000 0.644491 4.970375E-05 2.00000 8.737379E-03 0.614274 2.00000 3.610264E-04 0.905901
2.10000 0.684142 2.257595E-05 2.10000 0.626204 7.134984E-05 2.10000 8.188237E-03 0.631155 2.10000 3.175893E-04 0.910347
2.20000 0.671445 2.439662E-05 2.20000 0.607643 9.966306E-05 2.20000 3.437309E-03 0.649587 2.20000 3.847828E-05 0.914674
2.30000 0.658921 2.636680E-05 2.30000 0.588763 1.371713E-04 2.30000 5.906834E-04 0.666898 2.30000 2.018896E-04 0.918212
2.40000 0.646567 2.850380E-05 2.40000 0.569542 1.872420E-04 2.40000 1.199021E-03 0.680769 2.40000 2.279600E-04 0.921553
2.50000 0.634379 3.083119E-05 2.50000 0.549920 2.546647E-04 2.50000 1.850882E-03 0.692946 2.50000 2.762698E-05 0.924826
2.60000 0.622354 3.337174E-05 2.60000 0.529880 3.458717E-04 2.60000 2.201997E-03 0.704161 2.60000 1.045066E-04 0.927638
2.70000 0.610487 3.615420E-05 2.70000 0.509386 4.698597E-04 2.70000 2.767883E-03 0.714045 2.70000 1.058603E-04 0.930281
2.80000 0.598776 3.921089E-05 2.80000 0.488413 6.389660E-04 2.80000 2.139947E-03 0.723734 2.80000 9.618340E-05 0.932737
2.90000 0.587217 4.257846E-05 2.90000 0.466955 8.699156E-04 2.90000 6.292278E-04 0.733747 2.90000 1.226485E-05 0.935114
3.00000 0.575808 4.630103E-05 3.00000 0.445010 1.185337E-03 3.00000 1.415811E-04 0.742847 3.00000 7.197971E-05 0.937195];
% code to store all of the data into the proposed structure
for ii = 1:4
s(ii).Angle = Ir_10nm_Cr_10nm(:,1+3*(ii-1));
s(ii).Reflectivity = Ir_10nm_Cr_10nm(:,2+3*(ii-1));
s(ii).Transmission = Ir_10nm_Cr_10nm(:,3+3*(ii-1));
end
Then the matrix of reflectivity data across all four runs can be accessed as
Refl = [s.Reflectivity]
Refl = 31×4
1.0000 1.0000 1.0000 1.0000 0.9824 0.9808 0.9612 0.9709 0.9651 0.9620 0.9227 0.9382 0.9481 0.9434 0.8833 0.8925 0.9313 0.9252 0.8414 0.7760 0.9149 0.9071 0.7950 0.4147 0.8987 0.8893 0.7404 0.0264 0.8828 0.8716 0.6705 0.0509 0.8672 0.8541 0.5821 0.0090 0.8518 0.8366 0.4626 0.0063 0.8366 0.8193 0.2872 0.0083 0.8217 0.8020 0.1131 0.0032 0.8070 0.7848 0.0427 0.0014 0.7925 0.7675 0.0342 0.0020 0.7783 0.7503 0.0454 0.0020
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
How this is actually done, or it's even a good way to do it, depends on how the data gets into the workspace into the first place.
If you have different combinations of Ir and Cr then you might want to take this further as to how the data is stored and accessed across all combinations instead of storing the Ir and Cr values in the variable name for several variables. See TUTORIAL: Why Variables Should Not Be Named Dynamically for further discussion if interested.
There may be better alternatives, but combining three different variables from multiple tests into a single variable seems like it could eventually be confusing and difficult to extend. YMMV.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Descriptive Statistics dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by