A figure created within a for loop is not plotted (only the last one is shown)

Hello! I have the code attached.
A figure created within a for loop (fig_2.png) is not plotted (only the last one figure is shown -> fig_5.png).
I would like to get the figure on the left (see bottom) but I actually get the figure on the right, that is, it is missing the plotting of a curve (fig_2.png).

3 commentaires

hello again Alberto
I wish I could help you but I don't have the Image Processing Toolbox
but I can help you on the code that cause you trouble if you can send me the data (CoordinateMatrix) as mat file .
Hi! The codes are all there. What do you need? 'CoordinateMatrix' are two rx2 double matrices that I have no way to attach because I have already attached other files.
you can avoid the 10 files attachment limit by zipping all files , then you have again room for attaching 'CoordinateMatrix' data

Connectez-vous pour commenter.

 Réponse acceptée

hello again
so there was some figure calls still present in some functions (fun1, fun2 ,...)
I cleaned that so you have only the 3D plot
check the updates in the zip attached
I created a function "codeMN.m" that I used for this correction, but you should use "code.m" on your side
hope it helps

7 commentaires

No, I got the same result as I did.
Have you used the corrected functions from my zip ?
when I run "codeMN.m" (my debug version) I get only one figure (hFig3) and it's like :
Alberto Acri
Alberto Acri le 5 Déc 2022
Modifié(e) : Alberto Acri le 5 Déc 2022
Yes, I've seen your graph and it's fine.
I tried again and it works! Thank you!
Glab we finally managed it !
I ask for one last help.
In case I also have a white image (without closed curves) it gives me this error:
Output argument "Distance" (and possibly others) not assigned a value in the execution with "euclidean" function.
Error in DBSCAN (line 22)
Also should I add some "else" to the end of funcion_main?
in this case what is the array CoordinateMatrix ?
I assume it's empty so you have to make a test if CoordinateMatrix is empty or not
so your main loop in code.m should include this test :
for k = 1:length(imageFiles)
baseFileName = imageFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
imageArray1 = im2uint8(imageArray);
drawnow;
CoordinateMatrix = pic2points(imageArray1);
if ~isempty(CoordinateMatrix) % HERE
%======================================================
% check this part
X = CoordinateMatrix;
matrix_points = function_main(X);
%=======================================================
% Switch to the figure for the 3-D plotting:
figure(hFig3);
current_z = z(k) * ones(size(matrix_points, 1), 1);
plot3(matrix_points(:, 1), matrix_points(:, 2), current_z, 'k.');
hold on
%drawnow;
end
end

Connectez-vous pour commenter.

Plus de réponses (1)

Hi, you need to use the hold function after you display the first curve.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange

Produits

Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by