return the row and column number of the current subplot
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Leo Simon
am 12 Nov. 2016
Beantwortet: Walter Roberson
am 12 Nov. 2016
is there a property of `gca` that will return the row and column number of the current subplot?
e.g., I'd like a command that returns 2,3 if I'm at `subplot(3,4,7)` indicating that I'm at the second row, third column, etc
Obviously I can do some arithmetic on the 3 arguments of subplot, but it would be much cleaner if matlab provided the answer for me.
The reason I need this is that I want to insert a ylabel only if I'm in the first column and an xlabel only if I'm at the bottom row, so I'd like to be able to condition the xlabel and ylabel commands on these properties. Maybe there's another way to do this?
Thanks!
Leo
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 12 Nov. 2016
For the 3 x 4 array of subplots, index number 7:
[colnum, rownum] = ind2sub([4, 3], 7)
Notice that the normal use of ind2sub would be
[rownum, colnum] = ind2sub([3, 4], 7)
However, subplot is an exception in that it counts across rather than down
MATLAB does not provide any call like
[rownum, column] = current_subplot() %not a real thing
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Subplots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!