Error using horzcat Dimensions of arrays being concatenated are not consistent.
Show older comments
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']);
Accepted Answer
More Answers (1)
David Hill
on 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 Comments
Nisar Ahmed
on 29 Sep 2022
David Hill
on 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
on 29 Sep 2022
Categories
Find more on Creating and Concatenating 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!