如何请求多个输入,n 次
How to request multiple inputs, n number of times
对于下面的代码,我想取输入值 b
和 k
、n
次:
syms Q i w h2 h1 k
% n is number of layers for computation
n = input (' ')
for j = 1:n
k1 = input (' '); b1 = input (' ');
% up to...
k(n) = input (' '); b(n) = input (' ');
% so that i want to use the various inputs of b and k to calculate Q.
Qi=( -b(i) * k(i) )*((h2-h1)/w)
Q=symsum(Qi, i, 1, 3)
在循环中,您可以提示输入并将其存储到 k
和 b
值的数组中
% Pre-allocate k and b arrays
k = zeros(1, n);
b = zeros(1, n);
for ind = 1:n
% Prompt for the next k value
k(ind) = input('');
% Prompt for the next b value
b(ind) = input('');
end
或者,您可以直接提示用户输入数组
k = input('Please enter an array for k in the form [k1, k2, k3]');
b = input('Please enter an array for b in the form [b1, b2, b3]');
使用这些数组,您可以为 k
和 b
的每个值计算 Q
Q = (-b .* k)*((h2-h1)/w);
对于下面的代码,我想取输入值 b
和 k
、n
次:
syms Q i w h2 h1 k
% n is number of layers for computation
n = input (' ')
for j = 1:n
k1 = input (' '); b1 = input (' ');
% up to...
k(n) = input (' '); b(n) = input (' ');
% so that i want to use the various inputs of b and k to calculate Q.
Qi=( -b(i) * k(i) )*((h2-h1)/w)
Q=symsum(Qi, i, 1, 3)
在循环中,您可以提示输入并将其存储到 k
和 b
值的数组中
% Pre-allocate k and b arrays
k = zeros(1, n);
b = zeros(1, n);
for ind = 1:n
% Prompt for the next k value
k(ind) = input('');
% Prompt for the next b value
b(ind) = input('');
end
或者,您可以直接提示用户输入数组
k = input('Please enter an array for k in the form [k1, k2, k3]');
b = input('Please enter an array for b in the form [b1, b2, b3]');
使用这些数组,您可以为 k
和 b
Q
Q = (-b .* k)*((h2-h1)/w);