Filter löschen
Filter löschen

How to loop on undetermined number of figures and subplots?

10 Ansichten (letzte 30 Tage)
Eslam Hamed
Eslam Hamed am 17 Dez. 2015
Bearbeitet: Walter Roberson am 17 Dez. 2015
I have cell array (Images), and Matrix like this
Matrix =
Columns 1 through 27
1 2 3 4 5 6 7 8 9 10 21 28 29 11 12 13 14 15 16 17 19 18 20 22 23 24 25
1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3
Columns 28 through 29
26 27
3 3
Number of cells inside (Images) also equals 29 (of images links on my pc), so for each first row number (ex Images{15}) Image exists.
How can I loop over this Matrix for showing all images has value (1) -from the second row- together on a figure, and so on , for that I have 3 figures each has some not pre-determined number of Images, Also number of figures are not determined, they may be 2, 3, 5,.. etc.
Thank you in advance, I hope I made it clear.

Antworten (1)

Walter Roberson
Walter Roberson am 17 Dez. 2015
Bearbeitet: Walter Roberson am 17 Dez. 2015
subMatrix = Matrix(:,Matrix(:,2)==1);
Now size(subMatrix,2) tells you how many and the size is no longer undetermined.
This reflects a general strategy: if you have a fixed amount of data, then do a filtering pass on the data first to decide which ones will match, and then you will know how many you are dealing with.
An alternative approach is to loop through the data or other conditions but at each step that you would normally plot, instead record the appropriate data in a cell array or a struct. Then after everything is done, you can examine the size of the cell array or structure to know how many you have and then loop through the recorded data doing the actual plotting.
A second alternative approach is to loop through the data or other conditions and at each step create the plot in a separate figure that you do not make visible. Then after everything is done, you can examine how many such figures you generated and you can set the Parent property of each axes into a single figure, also setting the OuterPosition to the appropriate portion of the figure (which is what subplot does.) Setting the Parent property will move the graphics objects out of their temporary figure into the figure where you want everything displayed, so delete() the temporary figure afterwards.
You might also want to consider generating each plot in a different uitab() container; this is not the same as subplot(), but it also does not require postponing the plots or moving the graphics around afterwards.

Community Treasure Hunt

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

Start Hunting!

Translated by