How can I calculate the difference between two matrix with different size?
Show older comments
Hi everyone,
I have a problem in calculating the difference of the values of two matrices with different dimensions (1001-by-8501 and 6568-by-1638). Below is the script.
Thanks for your help.


Answers (2)
KSSV
on 28 Apr 2020
0 votes
Do inteprolation using interp2, get them to same size and get the difference. Also have a look on imresize.
Adam Danz
on 28 Apr 2020
0 votes
The 2nd line of code from the image you shared creates a 3D array of size m x n x 1. The 3d line attempts to concatenate that array along the 3rd dimension. It would have been easier if you included code rather than an image of code so I could copy-paste the lines of code rather than describe them.
The problem is, the value produced by the 3rd line does not have a size of m x n x 1. The error is caused at the 3rd line of code.
If you want to store them in a 3D array, they need to have the same shape and size. One of the matrices is 1001x8501 and the other is 6568x1638. If they are supposed to be the same size, something's wrong with the data or the way the data is being read in. If the sizes are correct, you'll need to explain how you expect the values to pair together.
5 Comments
Image Analyst
on 28 Apr 2020
You forgot to attach your txt files. Come on, make it easy for us to help you, not hard. Please attach them.
Also explain how you'd like to subtract them if they're not the same size. Read Adam's last paragraph again.
Giona Peter
on 28 Apr 2020
Edited: Walter Roberson
on 29 Apr 2020
Adam Danz
on 28 Apr 2020
Seeing the code is helpful but we can't move forward until the question in my answer is addressed. See the last paragraph of my answer.
The error happens here
mnt(:,:,2) = dlmread('export_mnt_j1_20cm.txt');
Giona Peter
on 29 Apr 2020
Adam Danz
on 29 Apr 2020
One of the matrices is 1001x8501 and the other is 6568x1638. If they are supposed to be the same size, something's wrong with the data or the way the data is being read in. If the sizes are correct, you'll need to explain how you expect the values to pair together.
Categories
Find more on Matrix Indexing 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!