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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by