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

1 回表示 (過去 30 日間)
Emily Turnbull
Emily Turnbull 2020 年 3 月 21 日
回答済み: Samatha Aleti 2020 年 3 月 24 日
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 Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by