简体   繁体   中英

How do I shorten an array in Matlab to prevent a dimension mismatch?

I'm taking in two arrays and comparing them. However, one array might be larger than the other.

So, how can I trim the larger array to the size of the smaller one to prevent a dimension mismatch?

Now, I'm using this code to trim the rows:

[nRows1, nCols1] = size(data1);

[nRows2, nCols2] = size(data2);

data1(nRows1 + 1:nRows2, :) = [];

But, this is still not working and it says that there is a dimension mismatch.

This should do it:

data1(size(data2, 1)+1:end, :) = [];
data2(size(data1, 1)+1:end, :) = [];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM