matlab - How can I change uipanel dimensions by using user input? -


i'm trying change panel , axes width , height values using user input. these values represent photograph's resolution. example, if user inputs 512*512, uipanel , axes' width , height change 512 , user work on workspace.

what tried far:

prompt = {'enter width', 'enter height'};  dlg_title = 'input'; num_lines = 1; def = {'256','256'}; answer = inputdlg(prompt,dlg_title,num_lines,def);  uipanel1.width = str2num(answer{1});  uipanel1.height = str2num(answer{2}); 

but size of uipanel1 not change.

here's code demonstrates how want can done, works (default matlab 2014b , onward).

%% //create figure uipanel & axes hfig = figure('units','pixels');       %// create new figure hfig.position = [100 100 600 600];     %// adjust figure's position hpan = uipanel(hfig,'units','pixels'); %// create new panel hpan.position = [150 150 300 300];     %// adjust panel's position hax = axes('parent',hpan,'units','normalized','position',[0 0 1 1]); %// new axes %% //ask user input prompt = {'enter width', 'enter height'};  dlg_title = 'input'; num_lines = 1; def = {'256','256'}; answer = cellfun(@str2double,inputdlg(prompt,dlg_title,num_lines,def));  %% //modify panel's position (axes stretch\shrink automatically fit) hpan.position(3:4) = answer; 

on older versions of matlab, may need different steps:

new_pos_vec = get(hpan,'position'); %// existing values new_pos_vec(3:4) = answer;          %// modify width & height set(hpan,'position', new_pos_vec);  %// update graphical properties 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -