Reverse 2D-lookup table: issues iterating through loops
10 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to implement a reverse 2d-lookup table as described in this thread:
The accepted answer provides this code for finding an input B1 at a specified A1 and C1 input:
A=[17.9 18.0 18.1 18.2]';
B=[0.4 0.5 0.6 0.7];
C=[67 89 95 108
74 92 110 123
80 97 115 127
84 106 119 135];
A1=18.046;
%Z=interp2(A,B,C,A1,B);
Z=interp2(A,B,C',A1,B);
C1=105;
B1=interp1(Z,B,C1);
I am trying to do a similar thing with inputs p,d, trying to get output s which I have stored in the variable so
[P,S] = meshgrid(54020:100:101320,0:10:3000);
d = -100.*(((((1373.393./4.002602).*8.3144598).*300)./((P+S).*0.4569)).*((log(P./(P+S)))-(P./(P+S))+1));
so = zeros(301, 474);
p = 54020:100:101320;
p = p';
s = 0:10:3000;
for i = 1: size(p)
%Z=interp2(A,B,C,A1,B);
Z=interp2(p,s,d,p(i),s);
for j = 1:size(s) -1
so(i,j)=interp1(Z,s,d(i,j));
end
end
I initialized the so variable as a matrix of zeros in the start to avoid a warning saying the size of so will be increasing throughout the iteration of the loops.
However, when running this code, so remains unpopulated and remains as a matrix of zeros
I am not sure why this is the case. Any help is much appreciated.
0 个评论
采纳的回答
Jyotsna Talluri
2020-7-7
In your code provided, size of array s is [1 301].
for j = 1:size(s)-1 % first element of the size array is considered
In above line j is empty row vector due to which loop excecution does not take place and hence the array 'so' remains as it is initialized.
Try replacing your code with below lines.
for i = 1:length(p)
%Z=interp2(A,B,C,A1,B);
Z=interp2(p,s,d,p(i),s);
for j = 1:length(s)
so(i,j)=interp1(Z,s,d(j,i));
end
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!