Pick a value from a matrix to produce another value in a matrix, and loop it

1 次查看(过去 30 天)
Im trying to fill a matrix with values using previous values within the matrix, however i cant make it loop so that it fills up a row, so far i have
h21=H(2,1)
h11=H(1,1)
h12=2*a*h21+(1-2*a)*h11+(a-B/(2*rw))*((dr*Q)/(pi*rw*T)
H(1,2)=h12
but i want to make it more general so it picks sequential j values from a row in a matrix and enters it in the j value after it (i.e. j+1), i was thinking it would look something like this but it isnt working:
h2j=H(2,j)
h1j=H(1,j)
h1jplus1=2*a*h2j+(1-2*a)*h1j+(a-B/(2*rw))*((dr*Q)/(pi*rw*T))
H(1,j+1)=h1jplus1

回答(1 个)

Samatha Aleti
Samatha Aleti 2020-3-24
Hi,
You can generalize it by using arrays and loops as follows:
H = [1 2 3 5; 4 5 6 5; 7 8 9 5]; % let
a = 1;
% Changing values of 1st row
for j = 1:size(H,2)-1
h21=H(2,j)
h11=H(1,j)
h12= a*h21+(1-2*a)*h11;
H(1,j+1)=h12
end

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by