Attempt to grow array along ambiguous dimension. How to fix?

6 views (last 30 days)
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 Comments
ALVARO TORRECILLAS CORTES
ALVARO TORRECILLAS CORTES on 27 Jun 2022
Now it is working in the right way, but the result that i have to obtain aren't the correct ones.
How can i do to separate the result from each image, because it only says:
Resultado_Imagen =
1.0996e-04
Resultado_Imagen =
7.2114e-04
Resultado_Imagen =
4.1018e-04
Resultado_Imagen =
4.0050e-04
But not separate in each image. Please help me because I don't know.

Sign in to comment.

Answers (2)

Steven Lord
Steven Lord on 27 Jun 2022
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 = 1×4
1 2 3 4
x(5) = 5 % x stays a row vector, just one element longer
x = 1×5
1 2 3 4 5
y = x.' % y is a column vector
y = 5×1
1 2 3 4 5
y(6) = 6 % y stays a column vector, just one element longer
y = 6×1
1 2 3 4 5 6
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 = 2×2
1 2 3 4
z(5) = 5
Attempt to grow array along ambiguous dimension.
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.

ALVARO TORRECILLAS CORTES
ALVARO TORRECILLAS CORTES on 27 Jun 2022
That it is the error
In nume (line 50)
numero_foci=max(max(unique(contar_foci)));
  3 Comments
ALVARO TORRECILLAS CORTES
ALVARO TORRECILLAS CORTES on 27 Jun 2022
Don't worry, I think I have solved the problem that I have with the programme.
Thank you so much!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!