MATLAB Answers

Error using horzcat function

4 views (last 30 days)
Ahmad Abbas
Ahmad Abbas on 25 Oct 2020
Edited: Image Analyst on 26 Oct 2020
Dear all
i got this error
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in dmatrix (line 9)
sp3=reshape([se./sd 0],181,251,391);
the code is
clear
load sr1695.asc
load sr1698.asc
sd = sr1695;
se = sr1695;
%The following forms 3D matrices, then a 2D projection along Z which eliminates the Z dependence.
sd3=reshape([sd(1:17763520) 0],181,251,391);
sp3=reshape([se./sd 0],181,251,391);
sd2=squeeze(mean(sd3,3));
sp2=squeeze(mean(sp3,3));
p2=hist3([reshape(sd2,1,[])', reshape(sp2,1,[])'],'Nbins',[100,100]);
thank you

  0 Comments

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 25 Oct 2020
Edited: Image Analyst on 26 Oct 2020
se and sd are presumably arrays with exactly 181 * 251 * 391 elements. However 0 is not. You're going to have to make 0 an array with the same number of rows and columns if you're going to stitch it next to the ratio array.
[rows, columns,slices] = size(se)
if rows*columns*slices == (181 * 251 * 391)
z = zeros(size(se));
stitchedArray = [se./sd, z];
sp3=reshape(stitchedArray, 181, 251, 391);
else
message = sprintf('Wrong number of elements to reshape.\nRows = %d, columns = %d, slices = %d, and product = %d\nbut (181 * 251 * 391) = %.1f', ...
rows, columns, slices, rows*columns*slices, (181 * 251 * 391));
uiwait(errorsld(message));
return;
end

  4 Comments

Show 1 older comment
Image Analyst
Image Analyst on 26 Oct 2020
Sorry, Typo. should be
uiwait(errordlg(message));
which will call the error dialog box. But since you go there, there is not the correct number of elements to resize it to that size. What is message? Paste it back here.
Ahmad Abbas
Ahmad Abbas on 26 Oct 2020
error dialog
Wrong number of elements to reshape
rows = 1776352, columns = 10, slices = 1 and product = 17763520
But (181*251*391) wrong number of elements tp reshape.
Rows = 17763521, Columns =
Walter Roberson
Walter Roberson on 26 Oct 2020
Yes? You added on a single zero to a vector, and now you are trying to reshape it back to the original size.
If you are going to add zeros, you need to do that for a complete row or complete column or complete page.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by