Pick a value from a matrix to produce another value in a matrix, and loop it
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Samatha Aleti
on 24 Mar 2020
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
0 Comments
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!