mtex-toolbox / mtex

MTEX is a free Matlab toolbox for quantitative texture analysis. Homepage:
http://mtex-toolbox.github.io/
GNU General Public License v2.0
281 stars 185 forks source link

incompatible sizes of grains(1).poly and grains(1).boundary #1555

Open ralfHielscher opened 2 years ago

ralfHielscher commented 2 years ago

Discussed in https://github.com/mtex-toolbox/mtex/discussions/1554

Originally posted by **vtvivian** September 14, 2022 Hi MTEX team, I am trying to select grains one by one in my EBSD map, e.g. ```matlab for n = 1:length(grains1), grains1(n); end ``` And get this intermittent error (e.g. n=786 in [this matlab data file](https://nplanywhere.npl.co.uk/u/sQrVuCaK1bGjCtW4/0858a4e7-3e7a-493a-9c6d-4652cbae02b3?l)) (ebsd = raw ebsd data, ebsd1 = cleaned up ebsd data, grains1 = calculated from ebsd1) ``` Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. Error in grain2d/subSet (line 68) inverseorder(ind2) = ind1; Error in grain2d/subsref (line 65) grains = subSet(grains,ind); ``` Which comes from a problem in ordering the gb segments in grain2d/subSet, because grains.poly is 2 rows longer than grains.boundary (it needs to be 1 row longer FNew to have the same number of rows as grains.boundary.F). ```matlab if length(grains) == 1 FNew = [grains.poly{1}(1:end-1).',grains.poly{1}(2:end).']; % remove inclusion embeddings if grains.inclusionId > 0 ie = sum(FNew == FNew(1),2)==1; ie([1,end-grains.inclusionId]) = false; [mtexForumData.zip](https://github.com/mtex-toolbox/mtex/files/9567851/mtexForumData.zip) FNew(ie,:) = []; end % sort minimum entry first FNew = sort(FNew,2); % sort such the order of F follows t [mtexForumData.zip](https://github.com/mtex-toolbox/mtex/files/9567844/mtexForumData.zip) he boundary [~,ind1] = sortrows(grains.boundary.F); [~,ind2] = sortrows(FNew); inverseorder(ind2) = ind1; grains.boundary = grains.boundary(inverseorder); end ``` Is this a bug, or did I do something unexpected when computing the grains?