Changing data diagonally in matrix based on formula and table

2 visualizzazioni (ultimi 30 giorni)
Hello,
Let say I have this matrix:
1 1 1 0 1 0 0 0
1 1 0 1 0 1 0 0
1 0 1 1 0 0 1 0
0 1 1 1 0 0 0 1
1 0 0 0 1 1 1 0
0 1 0 0 1 1 0 1
0 0 1 0 1 0 1 1
0 0 0 1 0 1 1 1
and this table:
kxx kyy kzz poroh
______ ______ ______ _______
1 5 6 80 0.12
2 5 6 80 0.21
3 13 62 23 0.20
4 14 81 14 0.22
5 10 16 63 0.23
6 12 62 36 0.26
7 11 45 41 0.21
8 5 5 5 0.19
and this equation:
(1/visc)*((2*kzz2*kzz1*az2*az1)/(kzz2*az2*delz+kz1*az1*delz)
%% All the variables are constant in this equation except (kzz) < which I have in the table.
this equation represent the diagonal started from column 5, I want to change the ones to the result of the equation based on the table
For example (1) in first row and column 5;
the equation will be
(1/visc)*((2*63*80*az2*az1)/(63*az2*delz+80*az1*delz)
kzz5 = 63 and kzz1 = 80
so based on the location on matrix, the code should take the value from the table.
this is the code that I used to change the data diagonally but it changed it to a constant number
k = -(x*y);
d = diag(XX,k);
n = d;
n(n==1) = 2;
XX = XX - diag(d,k) + diag(n,k);
Sorry if the code is not consistent but this is part of big project

Risposta accettata

Sajeer Modavan
Sajeer Modavan il 23 Mar 2019
unable to understand what you exactly looking. But this may help you
clc
clear
matrix = [ 1 1 1 0 1 0 0 0
1 1 0 1 0 1 0 0
1 0 1 1 0 0 1 0
0 1 1 1 0 0 0 1
1 0 0 0 1 1 1 0
0 1 0 0 1 1 0 1
0 0 1 0 1 0 1 1
0 0 0 1 0 1 1 1];
Table = [ 1 5 6 80 0.12
2 5 6 80 0.21
3 13 62 23 0.20
4 14 81 14 0.22
5 10 16 63 0.23
6 12 62 36 0.26
7 11 45 41 0.21
8 5 5 5 0.19];
kzz = Table(:,4);
visc = 1;
az1 = 1;
az2 = 1;
delz = 1;
for jj = 1:length(matrix(:,1))
for ii = 1:length(matrix(1,:))
Matrix(jj,ii) = (1/visc)*((2*kzz(ii)*kzz(jj)*az2*az1)/(kzz(ii)*az2*delz+kzz(jj)*az1*delz));
end
end
  5 Commenti
Sajeer Modavan
Sajeer Modavan il 23 Mar 2019
kzz = Table(:,4);
visc = 1; %Replace with original values
az1 = 1; %Replace with original values
az2 = 1; %Replace with original values
delz = 1; %Replace with original values
for jj = 1:4
ii = jj+4;
matrix(jj,ii) = (1/visc)*((2*kzz(ii)*kzz(jj)*az2*az1)/(kzz(ii)*az2*delz+kzz(jj)*az1*delz));
end

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by