"Arrays have incompatible sizes for this operation" error
Show older comments
As you can see in the attached photo, all of my arrays have the same size (3600 x 3601). So, I don't understand how I keep getting this error.

Answers (1)
the cyclist
on 3 Jun 2024
0 votes
It's difficult to know for sure, but I'm guessing those are the variables as they exist in the workspace, outside the function.
Inside the function, you are loading the variables. Are you sure they are all the same size inside of those *.MAT files? Try putting a breakpoint at line 11 of your code, and see what the variable sizes are there.
Can you upload the files here (and your actual code, not a screenshot), so we can try?
7 Comments
Jacey
on 3 Jun 2024
Torsten
on 3 Jun 2024
Before the line
Binary_Sum = Binary_Summary| ...
insert the lines
size(Binary_Summary)
size(Binary_Pitch)
size(Binary_SidePitch)
size(Binary_Clearance)
size(Binary_App)
size(Binary_Dep)
The output of all the six commands should be the same, namely [h,w].
Steven Lord
on 3 Jun 2024
You could contact Technical Support directly using this link. But before you do that, could you add one line of code to your function and show us what it displays when you run your code? Add this line between lines 10 and 11, right before the line where the error occurs.
whos
Copy and paste that whos output into a comment in this discussion. I suspect that at least one of the variables (BinarySummary would be my guess) is going to be a different size, and I'm guessing its size will be [3601 3600] instead of [3600 3601]
Jacey
on 3 Jun 2024
Steven Lord
on 3 Jun 2024
We don't know where those variables came from. So we don't know why GeoTifData has different values for its Height and Width properties or fields than you expected.
Those values sounded familiar, though. Searching I found your other question. It sounds like you manually changed those values. In that case I agree with the comment by @Stephen23 on that post: you're likely going to need to resample your data, not just change those values and hope everything automagically becomes the right size. Drawing an extra 0 on a $1 bill with a marker doesn't make it a $10 bill.
Jacey
on 3 Jun 2024
Steven Lord
on 3 Jun 2024
Take a look at the imresize function and/or this example from the interpolation documentation. If you're using Mapping Toolbox there may be functions you can use in that product as well, ones that are designed specifically for working with geographic data. Maybe georesize?
Categories
Find more on Resizing and Reshaping 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!