anyone knows how to address th Subscripted assignment dimension mismatch, I just cannot find why.

for i = length(indexLabel):-1:2
temxmat = newCenters((indexLabel(i-1)+1):indexLabel(i),1);
temymat = newCenters((indexLabel(i-1)+1):indexLabel(i),2);
ycoord = round(mean(newOutCenters((indexLabel(i-1)+1):indexLabel(i),2)));
distmat = temxmat(2:end)-temxmat(1:(end-1));
avdist = mean(distmat(distmat<threshold));
xmat =[];
ymat =[];
cellReg = find(distmat(distmat>=threshold));
for j = (length(cellReg)):-1:1
numofpts = floor(distmat(cellReg(j))/avdist-1);
addxmat =transpose(1:numofpts)*avdist+ones(numofpts,1)*temxmat(cellReg(j));
xmat = [temxmat(1:j);addxmat;temxmat((j+1):length(temxmat))];
addymat = ones(numofpts,1).*ycoord;
ymat = [temymat(1:j);addymat;temymat((j+1):length(temymat))];
end
newCenters((indexLabel(i-1)+1):length(xmat),1)=xmat;
newCenters((indexLabel(i-1)+1):length(ymat),2)=ymat;
end
Subscripted assignment dimension mismatch.

7 Comments

We can't run the code because it starts off with a bunch of predefined variables that we don't know what they are or their sizes. Plus you didn't give the full error message - only a small snippet from it. I'll try again tomorrow after you've read this link.
for i = length(indexLabel):-1:2
temxmat = newOutCenters((indexLabel(i-1)+1):indexLabel(i),1);
temymat = newOutCenters((indexLabel(i-1)+1):indexLabel(i),2);
ycoord = round(mean(newOutCenters((indexLabel(i-1)+1):indexLabel(i),2)));
distmat = temxmat(2:end)-temxmat(1:(end-1));
avdist = mean(distmat(distmat<threshold));
xmat =[];
ymat =[];
cellReg = find(distmat>=threshold);
for j = (length(cellReg)):-1:1
numofpts = floor(distmat(cellReg(j))/avdist-1);
addxmat =transpose(1:numofpts)*avdist+ones(numofpts,1)*temxmat(cellReg(j));
xmat = [temxmat(1:j);addxmat;temxmat((j+1):length(temxmat))];
addymat = ones(numofpts,1).*ycoord;
ymat = [temymat(1:j);addymat;temymat((j+1):length(temymat))];
end
prenewCenters(i,1:length(xmat),1)=xmat;
prenewCenters(i,1:length(ymat),2)=ymat;
end
newCenters = [];
[a,b] = size(prenewCenters(:,:,1));
newCenters(:,1)=prenewCenters(1:a,1:b,1);
newCenters(:,2)=prenewCenters(1:a,1:b,2);
figure,imshow(imCrop);
viscircles(newCenters,newradii);
I want to append values in some specific location of each row. The insertion point is labeled by the indexLabel matrix. In order to make the indexLabel work, I start append values from the last row. Somehow, I just cannot add the target values into the designated position based on the index labeled in the indexLabel. The system showed the Subscripted assignment dimension mismatch.
You need to include the complete error message, everything in red. If you do not include that then we will probably not bother to try to solve the problem.
And tell us in words what this code does. Something about circles perhaps? Make sure that if you paste your code into a new editor window (which is what we'd do) it will produce the error it said. Right now we'd just get errors about indexLabel and newOutCenters being undefined. And, like we've already asked, give the complete error message - ALL the red text, not just some of it.
Thank you very much, I have settle it down. The error results from the mismatch of the two matrix. eg. a = ones(2,2), b = ones(3), if we let a(:,1) = b, then it shows the mismatch error.

Answers (0)

This question is closed.

Asked:

on 24 Jul 2016

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!