Attempt to grow array along ambiguous dimension. How to fix?
15 次查看(过去 30 天)
显示 更早的评论
carpeta=uigetdir;
cd(carpeta);
I=dir('*.tif');
nI=size(I,1);
nombreTIFF=cell(nI,1);
PI=zeros(nI,1);
for i=1:nI
Celula = imread(I(i).name);
Celula_red = Celula(:,:,1);
Celula_green = Celula(:,:,2);
Celula_blue = Celula(:,:,3);
aver = fspecial('average', 5);
Celula_bluef = imfilter(Celula_blue, aver, 'same');
etiquetas=bwlabeln(Celula_full);
eti_grandes=etiquetas.*Celula_erode;
eti_finales=unique(eti_grandes);
eti_finales(eti_finales==0)=[];
mascara=zeros(size(Celula_blue));
for i=1:size(eti_finales,1)
mascara(etiquetas==eti_finales(i))=1;
end
[eti_mascara,n]=bwlabeln(mascara);
mask1=zeros(size(mascara));
mask1(eti_mascara==29)=1;
aver = fspecial('average', 5);
Celula_greenf = imfilter(Celula_green, aver, 'same');
ventana_green=imadjust(Celula_greenf,[0.55 1],[0 1]);
BW=edge(ventana_green,'log');
Celula_log_fill=imfill(BW,'holes');
Foci=double(Celula_greenf).*double(Celula_log_fill);
mascara_blue=double(mask1).*double(Celula_bluef);
mascara_green=double(mask1).*double(Foci);
area_celula=sum(mascara_blue(:)>0);
[contar_foci,nf]=bwlabeln(double(mask1).*double(Celula_log_fill));
numero_foci= nf;
foci_por_area=numero_foci/area_celula;
resultados_por_celula=zeros(size(unique(eti_mascara),1),1);
for e=1:n
mask1=zeros(size(mascara));
mask1(eti_mascara==i)=1;
mascara_blue=double(mask1).*double(Celula_bluef);
mascara_green=double(mask1).*double(Foci);
area_celula=sum(mascara_blue(:)>0);
contar_foci=bwlabeln(double(mask1).*double(Celula_log_fill));
numero_foci=max(max(unique(contar_foci)));
foci_por_area=numero_foci/area_celula;
resultados_por_celula(e)=foci_por_area;
end
Resultado_Imagen=mean(resultados_por_celula)
end
Attempt to grow array along ambiguous dimension.
11 个评论
回答(2 个)
Steven Lord
2022-6-27
This error occurs when you try to assign to an element beyond the last of a matrix but it's not clear what size the resulting larger array should be. If you try to assign to an element past the last of a vector, MATLAB assumes you want to keep the array as a vector and have it keep the same shape.
x = 1:4 % x is a row vector
x(5) = 5 % x stays a row vector, just one element longer
y = x.' % y is a column vector
y(6) = 6 % y stays a column vector, just one element longer
If you use linear indexing with a matrix, MATLAB doesn't know if you want to add another row or another column. If the code below did not error, what would you expect the size of z to be after the assignment to element 5? Should it be 2-by-3, 3-by-2, or 2-by-2-by-2?
z = [1 2; 3 4]
z(5) = 5
You haven't told us on which line the error occurs (if you run your code as a script file or as a function file rather than evaluating selection or copying the code into the Command Window the error should include that information) but likely one of your assignment statements isn't doing what you think it's doing. Find out which line is throwing the error and look at the sizes and values of the variables used on that line.
0 个评论
ALVARO TORRECILLAS CORTES
2022-6-27
3 个评论
Walter Roberson
2022-6-27
It would help to have the image to test with.
It would also help to have a copy of the error message indicating what matlab thinks is wrong
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!