In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Matlab how to maintain the size of each sub-image and add scroll bars to scroll up and down to view each sub-map, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.
Train of thought
(only consider the case that this series of sub-coordinate systems cannot be placed in the window)
The first thing to know is that the first two elements in the value of the Position attribute of the control in matlab's figure support negative numbers!
It can be understood that the coordinate system of figure or Panel of matlab is based on the point in the lower left corner. It belongs to the first quadrant in the range of figure or Panel. I'd better draw a picture.
So, we can use a Panel to hold these column sub-coordinate system, set the Panel to a fixed width, because the height must be higher than the height of the window, so we can set the vertical coordinate of this Panel to negative value (Abscissa is set to 0, the width is as wide as the window). The value of the ordinate is the opposite of the difference between the height of the Panel minus the height of the window.
How to scroll? You can directly use the Slider control (make a Slider if you are ugly, where Slider is vertical, and slider is the maximum state at the top), set the maximum value to the absolute value of the difference calculated above, and the minimum value to 0. Then to write the callback of Slider, each click on the last click to get the value of Slider, and then the value of the current Slider to do the difference; if the difference is negative, it means that slider is sliding down, so the corresponding Panel is moving upward, so directly use the ordinate of Panel to subtract the difference (minus negative is plus positive); the difference is positive is the opposite, the same.
However, I did not use subplot to draw subgraphs. I used the Grid layout I mentioned earlier to lay out several coordinate systems generated by axes, and then draw on these coordinates. Because I think it looks a little more comfortable than what subplot does. But it's pretty much the same if you have to use subplot.
Also, if you put Panel or other controls in the layout, you can't change its Positioning value (it's useless to change it), and I want this to form a horizontal layout with Slider. So I use two Panel here, one Panel (parent Panel) to lay out horizontally with Slider, and its child Panel puts some Axes there.
Due to time reasons, this code is only used to show that this idea is feasible, there is no optimization, interested eldest brothers and sisters can optimize and customize into a function, and then use this as a subplot.
For example:
1. To add a judgment, if a window can hold those sub-coordinate systems, there is no need to display Slider.
two。 Instead of using Slider, move the Panel by dragging the mouse up and down, and so on.
In addition, this idea can not only be used here, if you can not fit so many controls in an interface, you can use the ideas described in this article, but not only by using Slider to slide up and down, but by dragging the interface with the mouse.
Code
Function Multi_Subplot_Scroll (row, column)
% row: number of rows in the subgraph
% column: number of columns in the subgraph
%%
Clc
Close all
FMain = figure ('NumberTitle',' off',...
'Menubar', 'none',...
'Units', 'pixels',...
Position', [500,100,500,500],...
'Resize',' off')
%%
Create a horizontal layout
HBox = uiextras.HBox ('Parent', fMain)
% create a Panel that Panel uses to put child coordinates
Panel = uipanel ('Parent', HBox)
Create a slider for scrolling subplot
Slider = uicontrol ('Style',' slider',...
'Parent', HBox,...
'callback', {@ callback_Slider, fMain})
% Slider wide 20pix, the remaining widths are given to Panel
HBox.Widths = [- 1,20]
% calculate the width of the sub-coordinates at once, in fact, you don't have to (because it's in the layout)
% this is to roughly calculate the height of the sub-Panel.
Width_axes = fix (Panel.Position (3) / column);% hight_axes = width_axes
% calculate the height of the child Panel
Panel_Sub_Height = width_axes * row
%% this does not take into account the fact that the number of rows is so small that a window can be dropped (that is, only consider that the child Panel of the coordinate is higher than its parent Panel)
% calculated height difference
Diff_Height = Panel_Sub_Height-Panel.Position (4)
Set the maximum value of Slider to height difference
Slider.Max = diff_Height
Set the minimum value of Slider to 0
Slider.Min = 0
Set the current value of Slider to the maximum value of Slider (take slider to the top)
Slider.Value = Slider.Max
% initialize the value of slider when you last clicked slider Slider_PreviousValue is the maximum value of slider
Setappdata (fMain, 'Slider_PreviousValue', Slider.Max)
Create child Panel
Panel_Sub = uipanel ('Parent', Panel,...
'Units', 'pixels',...
'Position', [0,-diff_Height, Panel.Position (3), Panel_Sub_Height],...
'BackgroundColor',' k')
% Save child Panel
Setappdata (fMain, 'Panel_Sub', Panel_Sub)
Create grid layout
Grid_axes = uiextras.Grid ('Parent', Panel_Sub)
% draw each subgraph
For I = 1: row * column
Ax = axes ('Parent', Grid_axes)
Fplot (@ sin)
End
% set parameters for grid layout
Grid_axes.Heights =-ones (1, row)
Grid_axes.Widths =-ones (1, column)
End
Function callback_Slider (self, ~, fMain)
% get the last value of Slider
Slider_PreviousValue = getappdata (fMain, 'Slider_PreviousValue')
Get the value of the current Slider
Current_SliderValue = self.Value
% calculate the difference between the two
Diff_SliderValue = current_SliderValue-Slider_PreviousValue
% if negative indicates that Slider is declining, Panel_Sub should move upwards
% get the Panel of the coordinate system
Panel_Sub = getappdata (fMain, 'Panel_Sub')
% calculate the height to be moved
Reset Position for Panel_Sub
Panel_Sub.Position (2) = Panel_Sub.Position (2)-diff_SliderValue
Save the Value of the current Slider
Setappdata (fMain, 'Slider_PreviousValue', current_SliderValue)
End
(the two function are in the same folder)
In fact, it is quite simple; it may be a little troublesome to optimize it again.
Results:
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.