Error using horzcat Dimensions of arrays being concatenated are not consistent.

3 vues (au cours des 30 derniers jours)
Hi,
Please help me to solve this error?
If I write my code for a single array, it works well. The code is
VD = depth; rho = Rho(:,1);
ac = (1./Vp(:,1).*10^6).*0.000305;
VES2 = (1/0.0313)*log(0.38./Phi(:,1)); % Vertical effective stress by using Athy 1930, fo shale only.
vd = [0;VD]; vd1 = vd(1:end-1); vd2 = vd(2:end);
Z = vd2-vd1; % Thickness
OBP = Z.*rho.*0.0981; % OBP via density equation
OBP_i = 0;
OBP_b = cumsum([OBP_i OBP']);
OBP_b = OBP_b';
OBP_b = OBP_b(2:end); % OBP in bars
But if my Rho, Vp, ac, and Phi are matrix of size 165 85, and depth is of size 165 1. The following error appears in the code below
VD = depth; rho = Rho;
ac = (1./Vp.*10^6).*0.000305;
VES2 = (1/0.0313)*log(0.38./Phi); % Vertical effective stress by using Athy 1930, fo shale only.
vd = [0;VD]; vd1 = vd(1:end-1); vd2 = vd(2:end);
Z = vd2-vd1; % Thickness
OBP = Z.*rho.*0.0981; % OBP via density equation
OBP_i = 0;
OBP_b = cumsum([OBP_i OBP']);
OBP_b = OBP_b';
OBP_b = OBP_b(2:end);
The error is
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in MCMC2D_Test (line 53)
OBP_b = cumsum([OBP_i OBP']);

Réponse acceptée

dpb
dpb le 29 Sep 2022
Modifié(e) : dpb le 29 Sep 2022
In the code section where you combine OBP_i and OBP
OBP_i=0;
OBP_b = cumsum([OBP_i OBP']);
when you only consider a single column, OBP' is a row vector and so can put a 0 in front of it and all is well.
But, when you operate on the whole as an array, then OBP is a 2D array and OBP' is also a 2D array and so you're trying to add a single 0 to an array. To make that work as written would require
OBP_i=zeros(size(1,OBP,2));
OBP_b = cumsum([OBP_i.' OBP.'].');
Now, whether you'll be summing over the right direction is probably doubtful, it's not clear why you transposed OBP in the 1D case instead of writing
OBP_b = cumsum([OBP_i; OBP]);
I'd guess that what you really want instead of the above would be
OBP_i=zeros(size(1,OBP,2));
OBP_b = cumsum([OBP_i; OBP]);
instead and the result would be the cumulative sums, also by column.
One minor syntax note; instead of the following code snippet
...
vd = [0;VD]; vd1 = vd(1:end-1); vd2 = vd(2:end);
Z = vd2-vd1; % Thickness
you can use the builtin diff function and write
Z=[0;diff(VD)];
instead and eliminate the two temporary copies of VD.
  7 commentaires
dpb
dpb le 29 Sep 2022
You can hand verify the results as easily (more easily, actually) than I...
Nisar Ahmed
Nisar Ahmed le 29 Sep 2022
al right, thanks for you time and help

Connectez-vous pour commenter.

Plus de réponses (1)

David Hill
David Hill le 29 Sep 2022
VD = depth; rho = Rho;
ac = (1./Vp.*10^6).*0.000305;
VES2 = (1/0.0313)*log(0.38./Phi); % Vertical effective stress by using Athy 1930, fo shale only.
vd = [0;VD]; vd1 = vd(1:end-1); vd2 = vd(2:end);
Z = vd2-vd1; % Thickness
OBP = Z.*rho.*0.0981; % OBP via density equation
OBP_i = 0;
OBP=OBP';
OBP_b = cumsum([OBP_i OBP(:)'])';%OBP is a maxtrix, OBP(:) converts to an array that can be combined OBP_i
OBP_b = OBP_b(2:end);
  3 commentaires
David Hill
David Hill le 29 Sep 2022
Below runs. You need to tell us what you are trying to do with OBP_b (we cannot read your mind).
Rho=randi(100,165,85);
Vp=randi(100,165,85);
ac=randi(100,165,85);
Phi=randi(100,165,85);
depth=randi(100,165,1);
VD = depth; rho = Rho;
ac = (1./Vp.*10^6).*0.000305;
VES2 = (1/0.0313)*log(0.38./Phi); % Vertical effective stress by using Athy 1930, fo shale only.
vd = [0;VD]; vd1 = vd(1:end-1); vd2 = vd(2:end);
Z = vd2-vd1; % Thickness
OBP = Z.*rho.*0.0981; % OBP via density equation
OBP_i = 0;
OBP=OBP';
OBP_b = cumsum([OBP_i OBP(:)'])';%OBP is a maxtrix, OBP(:) converts to an array that can be combined OBP_i
OBP_b = OBP_b(2:end);
Nisar Ahmed
Nisar Ahmed le 29 Sep 2022
@David Hill I have input data e.g., depth, Rho, Vp, Phi and this data is in the form matrices i.e. 85 column. By using this data I want to comput VES_mpa (which will have 85 coulmn as well). The code given below is for (works well) for single array (one column)... I just need help how I can modify it for a matric.
In the above input data, depth is 165 1, by adding duplicate columns its size will also be 165 85, mean depth has same 85 colmun...
%% Computing effective pressure
VD = depth; rho = Rho;
ac = (1./Vp.*10^6).*0.000305;
VES2 = (1/0.0313)*log(0.38./Phi); % Vertical effective stress by using Athy 1930, fo shale only.
vd = [0;VD]; vd1 = vd(1:end-1); vd2 = vd(2:end);
% %Z=[0;diff(VD)];
Z = vd2-vd1; % Thickness
OBP = Z.*rho.*0.0981; % OBP via density equation
OBP_i = 0;
OBP = OBP';
% %OBP_i=zeros(size(Z));
OBP_b = cumsum([OBP_i OBP(:)'])';
% OBP_b = OBP_b';
OBP_b = OBP_b(2:end); % OBP in bars
OBP_MPa = OBP_b./10; % OBP in MPa
OBP_psi = OBP_b.*14.503778;
OBPg = OBP_psi./(VD.*3.28083); % AZ Thesis overburden pressure gradient normal (hydrostatic pressure) gradient
PP = OBP_MPa - VES2; % Pore pressure by the difference of OBP and Vertical stress.
Png = 0.42; dt_ml = 200; dt_m = 77;
PP_e = OBPg-(OBPg-Png).*((dt_m+(dt_ml-dt_m).*exp(-0.000245.*VD.*3.28083))./ac).^0.5;
PP_epsi = VD.*3.28.*PP_e;
VES2 = OBP_psi - PP_epsi; VES_mpa = VES2.*0.0068947573; % VES3 is vertical effective stress in MPa

Connectez-vous pour commenter.

Catégories

En savoir plus sur Stress and Strain dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by