mohsen...@gmail.com
unread,Aug 10, 2017, 4:34:20 PM8/10/17You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Hi all
I use Matlab to get visualized the results of our test measurements. For this purpose I write GUIs in Matlab. I generate the buttons, fields, checkboxes, axes, radio buttons . . . using “UICONTROL” command. I could use also GUIDE to generate the GUI, but it is not so precise for having really aligned elements on the GUI. Therefore I prefer the UICONTROL command.
Once I am finished with one project and want to begin with a new one using the old script/GUI and moving around its buttons and fields, it is a big action to calculate and edit all the position values (x, y, width and height) of each button, fields and so on.
Therefore I have written an AWK script (mv_matlab_buttons.awk) to move a group of Matlab elements which are lying near to each other from one side to another side of the GUI. As an example below, the file GUI_Code.m is shown with two elements. See the two lines 10 and 22 with the position values. On line 10 is the second last line and on line 22 is the last line of the command.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
gh.btnShowPOBs = uicontrol(...
gh.MainWindow,'Style','pushbutton',...
'String','ShowPOBs',...
'FontWeight','bold',...
'FontSize', 10,...
'Units','pixel',...
'BackgroundColor', [0.8 0 0], ...
'ForegroundColor', [1 1 1], ...
'Position',[475 FigY + 60 100 25],...
'Callback',{@btnShowPOBs});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
gh.btnGenPOBs = uicontrol(...
gh.MainWindow,'Style','pushbutton',...
'String','Gen POBs',...
'FontWeight','bold',...
'FontSize', 10,...
'Units','pixel',...
'BackgroundColor', [0.6 0 0], ...
'ForegroundColor', [1 1 1], ...
'Callback',{@btnGenPOBs},...
'Position',[475 FigY - 30 100 25]);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
After having used the AWK script with the command line:
mv_matlab_button.awk GUI_Code.m 50 20 0 0
It means: move the 2 buttons 50 in X and 20 in Y direction and do not change their widths and heights
I got the modification in the following file:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Out_GUI_Code.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
gh.btnShowPOBs = uicontrol(...
gh.MainWindow,'Style','pushbutton',...
'String','ShowPOBs',...
'FontWeight','bold',...
'FontSize', 10,...
'Units','pixel',...
'BackgroundColor', [0.8 0 0], ...
'ForegroundColor', [1 1 1], ...
'Position', [525 FigY+60+20 100 25], ...
'Callback',{@btnShowPOBs});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
gh.btnGenPOBs = uicontrol(...
gh.MainWindow,'Style','pushbutton',...
'String','Gen POBs',...
'FontWeight','bold',...
'FontSize', 10,...
'Units','pixel',...
'BackgroundColor', [0.6 0 0], ...
'ForegroundColor', [1 1 1], ...
'Callback',{@btnGenPOBs},...
'Position', [525 FigY-30+20 100 25
]);
==========================================================================
As you can see on the last line here, there is a failure. The string “]);” should be at the end of the Position line. This mistake happens, when the Position line is the last line of the UICONTROL command.
I have also printed the relevant values on the shell to see what the problem is. The last line of the New_Position seems to be somehow overwritten as you see in the following print commands:
mohsen@mohsen-PC /cygdrive/c/Users/mohsen/Desktop/neu
$ mv_matlab_button.awk GUI_Code.m 50 20 0 0
POSITION ==========> 475 FigY + 60 100 25
NR = 10
New_Position Before = 'Position', [525 FigY+60+20 100
PAR[4] = 25
New_Position After = 'Position', [525 FigY+60+20 100 25], ...
POSITION ==========> 475 FigY - 30 100 25
NR = 22
New_Position Before = 'Position', [525 FigY-30+20 100
PAR[4] = 25
]);_Position After = 'Position', [525 FigY-30+20 100 25
I am using AWK under CYGWIN and Windows 10.
Do you have any idea or can you see anything why the last output line
is so strange?
Thanks a lot for your help in advance.
Mohsen Owzar
And my AWK script is as the following:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#! /usr/bin/gawk -f
# Filename: mv_matlab_button.awk
# Author: Mohsen Owzar
# Date: 09.08.2017
####################################################################
# Description:
#
# Usage: mv_matlab_button.awk <Matlab GUI Code> <x y w h>
# mv_matlab_button.awk GUI_Code.m 50 20 0 0
#
####################################################################
# BEGIN Part
####################################################################
BEGIN {
FILE = ARGV[1]
par[1] = ARGV[2]
par[2] = ARGV[3]
par[3] = ARGV[4]
par[4] = ARGV[5]
delete ARGV[2]
delete ARGV[3]
delete ARGV[4]
delete ARGV[5]
DIGIT = "^[0-9]+$"
SIGN = "[-|+|*|/]"
LAST = "[;$]"
OutputFile = "Out_" FILE
print OutputFile > OutputFile
}
####################################################################
# MAIN Part
#####################################################################
{ # Find the line with "uicontrol" and get button name
if (/[ \t]*=[ \t]*uicontrol/) {Button = $1}
# If the line has Position than modify it, otherwise print the line
if (/Position/) {modifyPosition(par, Button)}
else {print $0 >> OutputFile}
}
####################################################################
# END Part
####################################################################
END {
print "\nDas File wurde modifiziert und als Folgendes abgespeichert:"
print "==========================================================="
print OutputFile
print ""
}
####################################################################
# function modifyPosition
####################################################################
function modifyPosition(par, but) {
split($0, ARRAY, ",")
Len = length(ARRAY[1])
POSITION = ARRAY[2]
####################################################################
# Check if the position line is the last line
####################################################################
LastLine = 0
if (POSITION ~ LAST) {
LastLine = 1
}
####################################################################
# Remove the left braket
####################################################################
sub(/\[/, "", POSITION)
############################################################
# Remove the last braket
############################################################
if (LastLine == 0) {sub(/\]/, "", POSITION)}
else {sub(/\]\);/, "", POSITION)}
print "POSITION ==========> " POSITION
split(POSITION, ARR)
if (POSITION ~ SIGN) {
POS = gensub(/[ \t]*([\+|\-|\*|\/])[ \t]*/, "\\1", "g", POSITION)
}
####################################################################
# Split four parts of the position line, x, y, w and h
####################################################################
N = split(POS, ARR)
for (i = 1; i <= N; i++) {
####################################################################
# If the part is a number than add the ARR[i] to parameter
# par[i] if it is non zero, otherwise take only ARR[i]
####################################################################
if (ARR[i] ~ DIGIT) {
if (par[i] != 0) {
PAR[i] = ARR[i] + par[i]
}
else {
PAR[i] = ARR[i]
}
}
####################################################################
# The part is not a number. It is an expression which has
# to be kept as expression by adding "+" Sign and the par[i]
# if par[i] is positive, otherwise concatenating ARR & par
####################################################################
else {
if (par[i] != 0) {
if (par[i] > 0) {PAR[i] = ARR[i] "+" par[i]}
else {PAR[i] = ARR[i] par[i]}
}
else {PAR[i] = ARR[i]}
}
}
LEER = ""
for (i = 1; i <= Len-10; i++) {
LEER = LEER " "
}
####################################################################
# Joining of the four parts of the position line
# At first the beginning of the line
####################################################################
New_Position = LEER "'Position', ["
####################################################################
# Next adding the first three parts with a space afterwards
####################################################################
for (i = 1; i <= 3; i++) {
New_Position = New_Position PAR[i] " "
}
####################################################################
# Next adding the last part of the "position line"
# depending of the position of the "position line"
# Is it in the middle of the UICONTRL-Command add -> "], ..."
# Is it as the last line of the UICONTRL-Command add -> "]);"
####################################################################
printf "NR = %s\n", NR
if (LastLine == 1) {
printf "New_Position Before = %s\n", New_Position
printf " PAR[%s] = %s\n", N,PAR[N]
New_Position = New_Position PAR[N] "]);"
printf "New_Position After = %s\n", New_Position
printf "\n"
}
else {
printf "New_Position Before = %s\n", New_Position
printf " PAR[%s] = %s\n", N,PAR[N]
New_Position = New_Position PAR[N] "], ..."
printf "New_Position After = %s\n", New_Position
printf "\n"
}
print New_Position >> OutputFile
}