Error using horzcat Dimensions of arrays being concatenated are not consistent.
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Nisar Ahmed
el 29 de Sept. de 2022
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']);
0 comentarios
Respuesta aceptada
dpb
el 29 de Sept. de 2022
Editada: dpb
el 29 de Sept. de 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 comentarios
dpb
el 29 de Sept. de 2022
You can hand verify the results as easily (more easily, actually) than I...
Más respuestas (1)
David Hill
el 29 de Sept. de 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 comentarios
David Hill
el 29 de Sept. de 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);
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!