How do I prepare spreadsheet data for use in interpn?
显示 更早的评论
I have an .xls spreadsheet with 294 rows of data. These rows represent multidimensional data, so there are 4 independent variables and 1 dependent variable on each row. I want to interpolate to find dependent variable values anywhere inside the domain.
The number of independent variables is: w = 2 x = 3 y = 7 z = 7 (hence the 2 x 3 x 7 x 7 = 294 rows).
I can sort the data in Excel, but I can't figure out how to load the data for input v required by interpn. I have tried generating a 4D array by loading each "3D column" of z as shown below, but it gives me an error.
RTU_3=xlsread('RTU_3_sim.xlsx','Data IP','A4:AX1183');
w=[75 85];
x=[55 65 75];
y=[60:10:120];
z=[0.7:0.1:1.3];
% Build a 4D array by iterating through the 7 values of z
for i=1:7
j=42*(i-1)+1;
k=42*i;
v(:,:,:,i) = RTU_3(j:k,16);
end
sample_interpolation=interpn(w,x,y,z,v,75.0001,55.0001,60.0001,0.95);
The error is:
??? Error using ==> interpn at 155
Wrong number of input arguments or some dimension of V is less than 2.
But the number of input arguments is 2N+1 as required, and V is shown as a 4-D Double in the workspace.
Can anybody help me understand what's going wrong, and how I should be getting the data into array "v"?
Thanks!
采纳的回答
更多回答(1 个)
the cyclist
2012-1-17
This sample code shows how v should be shaped. It needs to mimic the shape of each of your 4-D inputs.
w=[75 85];
x=[55 65 75];
y=[60:10:120];
z=[0.7:0.1:1.3];
v = rand(2,3,7,7);
interpolated_point = interpn(w,x,y,z,v,75.1,55.1,60.1,0.8);
It's a little hard for me to discern how you are trying to build up your v, but I am guessing that the way you are doing it, it does not end up as 2x3x7x7.
2 个评论
Canoe Commuter
2012-1-17
the cyclist
2012-1-17
You can use the reshape() command to do that. If you are careful of the ordering of the input, that should work find for you.
类别
在 帮助中心 和 File Exchange 中查找有关 Spreadsheets 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!