이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Interpolation using Excel Data
조회 수: 22 (최근 30일)
이전 댓글 표시
Hello. Newb here. I have a set of data in Excel (attached) that I would like to plot and interpolate and show the below and after plots (before interpolation and after). I have tried to follow various examples on interpolation, but am having a hard time understanding how to use my data in the code itself since I have an array of various answers. Right now my table is in 10s, and I want to interpolate the values between 10 and 20, 20 and 30,etc for inclination, and 300 and 310, etc for each.
I tried to see if I can figure out how to just interpret between the each and then manually enter into excel, but I'm having trouble here too.
What I'd REALLY love is all the values interpolated based on the data I have an plot the before (not interpolated) and after (after interpolation) on a 2D meshgrid.
Help??
thanks!
Veronica
채택된 답변
Star Strider
2023년 8월 18일
One approach —
% C1 = readcell('FluxData.xlsx')
T1 = readtable('FluxData.xlsx')
xvar = T1{1,3:end};
yvar = T1{2:end,2};
A = T1{2:end,3:end};
figure
surf(xvar, yvar, A)
colormap(turbo)
colorbar
xlabel('Inclination')
ylabel('Altitude')
zlabel('Flux')
[Xu,Yu] = meshgrid(xvar, yvar);
interpv = 5;
xq = linspace(min(xvar), max(xvar), numel(xvar)*interpv);
yq = linspace(min(yvar), max(yvar), numel(yvar)*interpv);
[Xi,Yi] = meshgrid(xq,yq);
Ai = interp2(Xu,Yu,A,Xi,Yi);
figure
surf(Xi, Yi, Ai)
colormap(turbo)
colorbar
xlabel('Inclination')
ylabel('Altitude')
zlabel('Flux')
.
댓글 수: 7
Veronica Vigil
2023년 8월 18일
Star - this is what I needed. Now, last question. If I wanted the raw data behind the plot, how do I pull that data? So it would include my original values for the 10s, and now include the 1s (hope that last part makes sense
Star Strider
2023년 8월 18일
Thank you!
The data that created the original plot are in the ‘xvar’, ‘yvar’, and‘A’ variables. The corresponding values for the interpolated plot are ‘xq’, ‘yq’, and ‘Ai’ variables.
The interpolation value (the scaling value) is the ‘interpv’ variable (and its assigned value). It controls the interpolation density, so here that is 5 times the original density. It can be set to any value you want (within reason). If the reulting surf plot is so dense that it appears black (because of the edge density), you can set the 'EdgeColor' to either 'interp' or 'off'. There are other options as well. See the surf documentation for those details.
.
Veronica Vigil
2023년 8월 18일
Is there a way I could write a code such that it also pulls these values into a table?
Veronica Vigil
2023년 8월 18일
I figured out how to get the values I want, but Now to figure out how to extract it into a table. I set it to 10 times the original density and will play with the colors as you mentioned.
Any idea how to pull them out? I know if I type just "Ai", it will display all of the data, but it's so much it gets cut off. I know there's a way to, for lack of a better term "export" the data into a table. Do you know how to do that?
Star Strider
2023년 8월 18일
Creating the matrix to write to the file requires a bit of creativity.
This approximately corresponds to the format of the original file —
% C1 = readcell('FluxData.xlsx')
T1 = readtable('FluxData.xlsx')
T1 = 92×20 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 Var11 Var12 Var13 Var14 Var15 Var16 Var17 Var18 Var19 Var20
____________ ____ _________ _________ __________ _________ _________ _________ _________ _________ _________ _________ _________ _________ _________ _________ _________ _________ __________ _________
{0×0 char } NaN 10 20 30 40 50 60 70 80 90 98 100 110 120 130 140 150 160 170
{'Altitude'} 300 3.421e-08 4.059e-08 5.242e-08 4.567e-08 4.147e-08 4.287e-08 3.951e-08 5.478e-08 6.376e-08 5.2e-08 4.925e-08 5.238e-08 6.125e-08 8.317e-08 7.686e-08 9.879e-08 8.283e-08 1.058e-07
{0×0 char } 310 4.252e-08 4.075e-08 3.614e-08 3.472e-08 3.756e-08 4.766e-08 5.917e-08 9.377e-08 8.392e-08 6.897e-08 7.078e-08 6.61e-08 6.631e-08 6.824e-08 7.123e-08 7.971e-08 7.926e-08 1.074e-07
{0×0 char } 320 7.164e-08 5.049e-08 5.291e-08 5.516e-08 5.649e-08 5.612e-08 7.005e-08 9.938e-08 1.056e-07 7.96e-08 8.31e-08 7.555e-08 7.661e-08 8.905e-08 9.13e-08 9.877e-08 9.812e-08 1.451e-08
{0×0 char } 330 6.99e-08 6.738e-08 6.263e-08 6.359e-08 7.276e-08 7.841e-08 9.61e-08 1.328e-07 1.195e-07 1.03e-07 8.31e-08 9.903e-08 1.084e-07 1.45e-07 1.176e-07 1.195e-07 1.273e-07 1.55e-07
{0×0 char } 340 8.915e-08 9.009e-08 8.952e-08 9.115e-08 1.041e-07 1.155e-07 1.155e-07 1.383e-07 1.521e-07 1.588e-07 1.49e-07 1.401e-07 1.601e-07 1.576e-07 1.398e-07 1.505e-07 1.517e-07 1.806e-07
{0×0 char } 350 6.648e-08 6.913e-08 7.1654e-08 8.288e-08 9.692e-08 9.374e-08 1.076e-07 1.449e-07 1.487e-07 1.495e-07 1.557e-07 1.37e-07 1.464e-07 1.74e-07 1.494e-07 1.228e-07 1.298e-07 1.342e-07
{0×0 char } 360 3.693e-08 3.502e-08 3.39e-08 5.745e-08 5.058e-08 4.978e-08 5.355e-08 5.868e-08 5.487e-08 6.224e-08 6.003e-08 6.538e-08 6.881e-08 7.896e-08 8.467e-08 7.157e-08 8.227e-08 1.002e-07
{0×0 char } 370 5.007e-08 4.519e-08 6.075e-08 5.858e-08 7.319e-08 7.767e-08 8.992e-08 1.312e-07 1.2e-07 1.082e-07 1.036e-07 9.134e-08 8.91e-08 1.035e-07 8.078e-08 9.484e-08 8.471e-08 1.128e-07
{0×0 char } 380 1.015e-07 1.218e-07 1.18e-07 1.095e-07 1.225e-07 1.182e-07 1.43e-07 1.751e-07 1.67e-07 1.949e-07 1.854e-07 1.649e-07 1.544e-07 1.816e-07 1.681e-07 1.639e-07 2.052e-07 1.928e-07
{0×0 char } 390 1.736e-07 1.719e-07 1.778e-07 1.762e-07 1.878e-07 2.038e-07 2.198e-07 2.71e-07 2.676e-07 2.728e-07 2.714e-07 2.668e-07 2.832e-07 3.08e-07 3.1e-07 3.63e-07 3.356e-07 3.484e-07
{0×0 char } 400 2.332e-07 2.047e-07 1.974e-07 2.229e-07 2.276e-07 2.164e-07 2.279e-07 2.537e-07 2.677e-07 2.801e-07 2.875e-07 2.813e-07 3.398e-07 5.263e-07 4.309e-07 4.082e-07 4.348e-07 4.333e-07
{0×0 char } 410 2.381e-07 2.241e-07 2.334e-07 2.295e-07 2.518e-07 2.828e-07 3.154e-07 3.751e-07 4.007e-07 3.984e-07 4.108e-07 4.561e-07 5.326e-07 6.362e-07 4.896e-07 4.367e-07 4.64e-07 3.828e-07
{0×0 char } 420 1.659e-07 1.775e-07 1.725e-07 1.807e-07 1.963e-07 2.064e-07 2.414e-07 3.832e-07 3.569e-07 3.665e-07 3.226e-07 2.415e-07 2.383e-07 2.505e-07 2.408e-07 2.306e-07 1.2265e-07 2.262e-07
{0×0 char } 430 2.06e-07 2.134e-07 2.252e-07 2.396e-07 2.562e-07 2.745e-07 2.848e-07 3.262e-07 3.018e-07 2.898e-07 2.913e-07 3.03e-07 3.328e-07 3.469e-07 3.256e-07 2.855e-07 2.664e-07 2.707e-07
{0×0 char } 440 2.179e-07 2.418e-07 2.155e-07 2.035e-07 2.293e-07 2.359e-07 2.696e-07 3.338e-07 3.318e-07 3.271e-07 3.321e-07 3.001e-07 2.99e-07 3.114e-07 2.979e-07 2.859e-07 3.131e-07 2.735e-07
xvar = T1{1,3:end};
yvar = T1{2:end,2};
A = T1{2:end,3:end};
% figure
% surf(xvar, yvar, A)
% colormap(turbo)
% colorbar
% xlabel('Inclination')
% ylabel('Altitude')
% zlabel('Flux')
[Xu,Yu] = meshgrid(xvar, yvar);
interpv = 5;
xq = linspace(min(xvar), max(xvar), numel(xvar)*interpv);
yq = linspace(min(yvar), max(yvar), numel(yvar)*interpv);
[Xi,Yi] = meshgrid(xq,yq);
Ai = interp2(Xu,Yu,A,Xi,Yi);
% figure
% surf(Xi, Yi, Ai)
% colormap(turbo)
% colorbar
% xlabel('Inclination')
% ylabel('Altitude')
% zlabel('Flux')
[r,c] = size(Ai); % Create Matrix To Write
M = NaN(r+1,c+1);
M(2:r+1, 2:c+1) = Ai;
M(1,2:end) = xq;
M(2:end,1) = yq;
M % Display Matrix
M = 456×91
NaN 10.0000 11.7978 13.5955 15.3933 17.1910 18.9888 20.7865 22.5843 24.3820 26.1798 27.9775 29.7753 31.5730 33.3708 35.1685 36.9663 38.7640 40.5618 42.3596 44.1573 45.9551 47.7528 49.5506 51.3483 53.1461 54.9438 56.7416 58.5393 60.3371
300.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
301.9824 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
303.9648 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
305.9471 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
307.9295 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
309.9119 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
311.8943 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
313.8767 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
315.8590 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
writematrix(M,'FluxDataInterp.xlsx') % Write Matrix To File
InterpFlux = readmatrix('FluxDataInterp.xlsx') % Check Written File
InterpFlux = 456×91
NaN 10.0000 11.7978 13.5955 15.3933 17.1910 18.9888 20.7865 22.5843 24.3820 26.1798 27.9775 29.7753 31.5730 33.3708 35.1685 36.9663 38.7640 40.5618 42.3596 44.1573 45.9551 47.7528 49.5506 51.3483 53.1461 54.9438 56.7416 58.5393 60.3371
300.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
301.9824 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
303.9648 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
305.9471 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
307.9295 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
309.9119 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
311.8943 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
313.8767 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
315.8590 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
xq = InterpFlux(1,2:end) % Retrieve Data
xq = 1×90
10.0000 11.7978 13.5955 15.3933 17.1910 18.9888 20.7865 22.5843 24.3820 26.1798 27.9775 29.7753 31.5730 33.3708 35.1685 36.9663 38.7640 40.5618 42.3596 44.1573 45.9551 47.7528 49.5506 51.3483 53.1461 54.9438 56.7416 58.5393 60.3371 62.1348
yq = InterpFlux(2:end,2) % Retrieve Data
yq = 455×1
1.0e-05 *
0.0034
0.0036
0.0038
0.0039
0.0041
0.0042
0.0048
0.0054
0.0060
0.0065
Ai = InterpFlux(2:end,2:end) % Retrieve Data
Ai = 455×90
1.0e-05 *
0.0034 0.0035 0.0037 0.0038 0.0039 0.0040 0.0042 0.0044 0.0046 0.0048 0.0050 0.0052 0.0051 0.0050 0.0049 0.0048 0.0047 0.0045 0.0045 0.0044 0.0043 0.0042 0.0042 0.0042 0.0042 0.0042 0.0042 0.0043 0.0043 0.0042
0.0036 0.0037 0.0038 0.0038 0.0039 0.0040 0.0041 0.0043 0.0044 0.0046 0.0047 0.0049 0.0048 0.0047 0.0046 0.0045 0.0044 0.0043 0.0043 0.0042 0.0042 0.0041 0.0041 0.0041 0.0042 0.0042 0.0043 0.0043 0.0044 0.0044
0.0038 0.0038 0.0039 0.0039 0.0040 0.0040 0.0041 0.0042 0.0043 0.0044 0.0045 0.0046 0.0045 0.0044 0.0044 0.0043 0.0042 0.0041 0.0041 0.0041 0.0040 0.0040 0.0040 0.0041 0.0041 0.0042 0.0043 0.0044 0.0045 0.0045
0.0039 0.0039 0.0040 0.0040 0.0040 0.0041 0.0041 0.0041 0.0042 0.0042 0.0042 0.0043 0.0042 0.0042 0.0041 0.0040 0.0040 0.0039 0.0039 0.0039 0.0039 0.0039 0.0039 0.0040 0.0041 0.0042 0.0044 0.0045 0.0046 0.0047
0.0041 0.0041 0.0041 0.0041 0.0041 0.0041 0.0041 0.0040 0.0040 0.0040 0.0040 0.0040 0.0039 0.0039 0.0038 0.0038 0.0037 0.0037 0.0037 0.0038 0.0038 0.0038 0.0038 0.0039 0.0041 0.0042 0.0044 0.0045 0.0047 0.0048
0.0042 0.0042 0.0042 0.0042 0.0041 0.0041 0.0040 0.0040 0.0039 0.0038 0.0037 0.0036 0.0036 0.0036 0.0036 0.0035 0.0035 0.0035 0.0035 0.0036 0.0036 0.0037 0.0037 0.0039 0.0041 0.0043 0.0044 0.0046 0.0048 0.0050
0.0048 0.0047 0.0046 0.0045 0.0044 0.0043 0.0042 0.0042 0.0041 0.0041 0.0040 0.0039 0.0039 0.0039 0.0039 0.0039 0.0039 0.0039 0.0039 0.0040 0.0040 0.0041 0.0041 0.0042 0.0044 0.0045 0.0047 0.0048 0.0050 0.0052
0.0054 0.0052 0.0050 0.0049 0.0047 0.0045 0.0044 0.0044 0.0044 0.0043 0.0043 0.0043 0.0043 0.0043 0.0043 0.0043 0.0043 0.0043 0.0043 0.0044 0.0044 0.0044 0.0045 0.0046 0.0047 0.0048 0.0049 0.0050 0.0051 0.0054
0.0060 0.0057 0.0055 0.0053 0.0050 0.0048 0.0046 0.0046 0.0046 0.0046 0.0046 0.0046 0.0046 0.0046 0.0046 0.0046 0.0047 0.0047 0.0047 0.0048 0.0048 0.0048 0.0049 0.0049 0.0050 0.0051 0.0051 0.0052 0.0053 0.0055
0.0065 0.0062 0.0059 0.0056 0.0053 0.0050 0.0048 0.0049 0.0049 0.0049 0.0049 0.0049 0.0050 0.0050 0.0050 0.0050 0.0051 0.0051 0.0051 0.0051 0.0052 0.0052 0.0052 0.0053 0.0053 0.0053 0.0054 0.0054 0.0055 0.0057
This should do everything you want with the interpolated data.
.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)