error with "The matrix MSG in ENCODE must have K columns" - matlab

im working on a video steganography using LSB technique..im using traffic.avi and xylophone.mpg as the cover medium and when im using the licence.txt file (in the attach file) to encode into the video it runs well however when im using a short messsage for the input text it shows an error which is
"The matrix MSG in ENCODE must have K columns." and sometimes when use short text it gives error "msg is too long to encode"
i have no idea what does this 2 set of coding means and how to edit the code to make it possible to encode a short msg...below this is some of the code that i guess relate to this problem
num2add = 80-length(msg); % Number of spaces to add to end of MSG.
if num2add < 0, error('This message is too long to encode.'), end
newmsg = [msg,repmat(' ',1,num2add)]; % 80 chars always encoded.
msgmat = dec2bin(newmsg)-48; % Each row is a bin. rep. of an ascii char.
and also this coding
if m_msg == 1
type_flag = 2; % binary vector
[msg, added] = vec2mat(msg, k);
elseif m_msg ~= k
error('comm:encode:InvalidMatrixColumnSize','The matrix MSG in ENCODE must have K columns.');
BELOW THIS IS THE FULL ENCODE CODING continue after the first part of the above coding!
B = pic1(:,:,1); [piclngth pichght] = size(B); % Choose the first page.
dim1 = piclngth-2; dim2 = pichght-3; keyb = key(end:-1:1);
rows = cumsum(double(key));
columns = cumsum(double(keyb)); % Coord pairs for KEY (rows,columns)
A = zeros(dim1,dim2); % This matrix will house the hiding points.
A = crtmtrx(A,rows,columns,dim1,dim2,key);
idx = find(A==1); % This same index will be used for pic matrix.
for vv = 1:80 % This is the encoder.
for uu = 1:8
if msgmat(vv,uu)==1;
if rem(B(idx(uu+8*(vv-1))),2)==0
if(frame==1)
disp('some pixel value of original frame');
B(idx(uu+8*(vv-1)))
end
B(idx(uu+8*(vv-1))) = B(idx(uu+8*(vv-1)))+1;
if(frame==1)
disp('some pixel value of stegno video frame');
B(idx(uu+8*(vv-1)))
end
end
elseif rem(B(idx(uu+8*(vv-1))),2)==1
if(frame==1)
disp('some pixel value of original frame');
B(idx(uu+8*(vv-1)))
end
B(idx(uu+8*(vv-1))) = B(idx(uu+8*(vv-1)))-1;
if(frame==1)
disp('some pixel value of stegno video frame');
B(idx(uu+8*(vv-1)))
end
end
end
end
global newpic;
newpic = pic1; newpic(:,:,1) = B;
f(frame) = im2frame(newpic);
end
frameRate = get(vidObj,'FrameRate');
movie2avi(f,'stegano_video.avi','compression','None', 'fps', 20);
success = 1;
function A = crtmtrx(A,rows,columns,dim1,dim2,key)
% Creates the matrix used to find the points to hide the message.
jj = 1; idx = 1;
while 640 > length(idx) % Need 560 points to hide 80 characters.
for ii = 1:length(rows)
if rows(ii) < dim1
rows(ii) = rem(dim1,rows(ii))+1;
else
rows(ii) = rem(rows(ii),dim1)+1;
end
if columns(ii) < dim2
columns(ii) = rem(dim2,columns(ii))+1;
else
columns(ii) = rem(columns(ii),dim2)+1;
end
A(rows(ii),columns(ii)) = 1;
end
rows = jj*cumsum(double(columns))+round(dim2/2); % Each pass is diff.
columns = jj*cumsum(double(rows))+round(dim1/2);
if jj > ceil(640/length(key))+2 % Estimate how many iters. needed.
idx = find(A==1);
end
jj = jj+1;
end
this is some of the input text and the right one is the encypted txt

The code that triggers the error is pretty clear:
num2add = 80-length(msg); % Number of spaces to add to end of MSG.
if num2add < 0, error('This message is too long to encode.'), end
So basically you will get the error as soon as there are more than 80 characters in msg. I am not sure whether the 80 is meaningfull, you can try to increase it but that may break something else.

Related

MATLAB to Scilab conversion: mfile2sci error "File contains no instruction"

I am very new to Scilab, but so far have not been able to find an answer (either here or via google) to my question. I'm sure it's a simple solution, but I'm at a loss. I have a lot of MATLAB scripts I wrote in grad school, but now that I'm out of school, I no longer have access to MATLAB (and can't justify the cost). Scilab looked like the best open alternative. I'm trying to convert my .m files to Scilab compatible versions using mfile2sci, but when running the mfile2sci GUI, I get the error/message shown below. Attached is the original code from the M-file, in case it's relevant.
I Searched Stack Overflow and companion sites, Google, Scilab documentation.
The M-file code follows (it's a super basic MATLAB script as part of an old homework question -- I chose it as it's the shortest, most straightforward M-file I had):
Mmax = 15;
N = 20;
T = 2000;
%define upper limit for sparsity of signal
smax = 15;
mNE = zeros(smax,Mmax);
mESR= zeros(smax,Mmax);
for M = 1:Mmax
aNormErr = zeros(smax,1);
aSz = zeros(smax,1);
ESR = zeros(smax,1);
for s=1:smax % for-loop to loop script smax times
normErr = zeros(1,T);
vESR = zeros(1,T);
sz = zeros(1,T);
for t=1:T %for-loop to carry out 2000 trials per s-value
esr = 0;
A = randn(M,N); % generate random MxN matrix
[M,N] = size(A);
An = zeros(M,N); % initialize normalized matrix
for h = 1:size(A,2) % normalize columns of matrix A
V = A(:,h)/norm(A(:,h));
An(:,h) = V;
end
A = An; % replace A with its column-normalized counterpart
c = randperm(N,s); % create random support vector with s entries
x = zeros(N,1); % initialize vector x
for i = 1:size(c,2)
val = (10-1)*rand + 1;% generate interval [1,10]
neg = mod(randi(10),2); % include [-10,-1]
if neg~=0
val = -1*val;
end
x(c(i)) = val; %replace c(i)th value of x with the nonzero value
end
y = A*x; % generate measurement vector (y)
R = y;
S = []; % initialize array to store selected columns of A
indx = []; % vector to store indices of selected columns
coeff = zeros(1,s); % vector to store coefficients of approx.
stop = 10; % init. stop condition
in = 0; % index variable
esr = 0;
xhat = zeros(N,1); % intialize estimated x signal
while (stop>0.5 && size(S,2)<smax)
%MAX = abs(A(:,1)'*R);
maxV = zeros(1,N);
for i = 1:size(A,2)
maxV(i) = abs(A(:,i)'*R);
end
in = find(maxV == max(maxV));
indx = [indx in];
S = [S A(:,in)];
coeff = [coeff R'*S(:,size(S,2))]; % update coefficient vector
for w=1:size(S,2)
r = y - ((R'*S(:,w))*S(:,w)); % update residuals
if norm(r)<norm(R)
index = w;
end
R = r;
stop = norm(R); % update stop condition
end
for j=1:size(S,2) % place coefficients into xhat at correct indices
xhat(indx(j))=coeff(j);
end
nE = norm(x-xhat)/norm(x); % calculate normalized error for this estimate
%esr = 0;
indx = sort(indx);
c = sort(c);
if isequal(indx,c)
esr = esr+1;
end
end
vESR(t) = esr;
sz(t) = size(S,2);
normErr(t) = nE;
end
%avsz = sum(sz)/T;
aSz(s) = sum(sz)/T;
%aESR = sum(vESR)/T;
ESR(s) = sum(vESR)/T;
%avnormErr = sum(normErr)/T; % produce average normalized error for these run
aNormErr(s) = sum(normErr)/T; % add new avnormErr to vector of all av norm errors
end
% just put this here to view the vector
mNE(:,M) = aNormErr;
mESR(:,M) = ESR;
% had an 'end' placed here, might've been unmatched
mNE%reshape(mNE,[],Mmax)
mESR%reshape(mESR,[],Mmax)]
figure
dimx = [1 Mmax];
dimy = [1 smax];
imagesc(dimx,dimy,mESR)
colormap gray
strESR = sprintf('Average ESR, N=%d',N);
title(strESR);
xlabel('M');
ylabel('s');
strNE = sprintf('Average Normed Error, N=%d',N);
figure
imagesc(dimx,dimy,mNE)
colormap gray
title(strNE)
xlabel('M');
ylabel('s');
The command used (and results) follow:
--> mfile2sci
ans =
[]
****** Beginning of mfile2sci() session ******
File to convert: C:/Users/User/Downloads/WTF_new.m
Result file path: C:/Users/User/DOWNLO~1/
Recursive mode: OFF
Only double values used in M-file: NO
Verbose mode: 3
Generate formatted code: NO
M-file reading...
M-file reading: Done
Syntax modification...
Syntax modification: Done
File contains no instruction, no translation made...
****** End of mfile2sci() session ******
To convert the foo.m file one has to enter
mfile2sci <path>/foo.m
where stands for the path of the directoty where foo.m is. The result is written in /foo.sci
Remove the ```` at the begining of each line, the conversion will proceed normally ?. However, don't expect to obtain a working .sci file as the m2sci converter is (to me) still an experimental tool !

Matlab - How can I write the values to an excel in a nested for loop

I have an Image which is 1944(R) x 2592 (C). I would like to take one column at a time; treating each column as an Image and calculate how many pixels among each row of that column contains value > half(max) value of that column. Those number of pixels are to be written to the excel sheet corresponding to it's respective column.
Image: the image
Here is what I have tried so far, I am not able to write it successfully.
clc;
sig = rgb2gray(imread('1.bmp')); % read in the image.
% imshow(sig);
ArraySize = size(sig); %1944(R) x 2592 (C)
[maxval, maxloc] = max(sig(:)); % Gives the max and the location
maxval; % max value
[maxloc_row, maxloc_col] = ind2sub(size(sig), maxloc); % convert logical
%-------------------------------------------------------------------%
% Count pixels through each column > half(max) value of that column
%-------------------------------------------------------------------%
newfilename = 'Results.csv'; % write new values to .csv files
Array = zeros(2592,2);
% % R = Array(:,1);
% y = Array(:,2);
for a = 1: 2592% maxloc_row = 635 maxloc_col = 1094
[a_maxval, a_maxloc] = max(sig(:,a)); % search max among every column.
% maxloc is the row at which maxval is.
newval = a_maxval/2; % averaged max value
% New structure for find width
x = 0;
x = Array(:, 1);
for b = 1: 1944 % maxloc_row = 635 maxloc_col = 1094
% R = b;
if sig(b,a) > newval
x=x+1;
end
end % End row search
x;
% y = x*(2.2); % pixels into microns
output = [num2cell(x)];
xlswrite(newfilename, output);
end % End column search
I think csvwrite can write data to csv file. Here's what you can try:
place output = []; somewhrere at top, says below clc;
then, replace
output = [num2cell(x)]; with output = [output x];
and
xlswrite(newfilename, output); with csvwrite(newfilename, output); but place it at the end of program because output has all x inside.
I have tried and it works.

How to extract Shape and Texture vertices from .wrl(VRML) file to .mat

I have 3D data. And there is a .wrl(VRML) file in it. I need to load that file and then extract only the shape and texture vertices (x,y,z)points. How to do that?
This is the code i have:
%/*********************************************************************************
% FUNCTION NAME : read_vrml
% AUTHOR : G. Akroyd
% PURPOSE : reads a VRML or Inventor file and stores data points and connectivity
% in arrays ready for drawing wireframe images.
%
% VARIABLES/PARAMETERS:
% i/p filename name of vrml file
% o/p nel number of geometry parts (elements) in file
% o/p w3d geometry structure ;-
% w3d.pts array of x y z values for each element
% w3d.knx array of connection nodes for each element
% w3d.color color of each element
% w3d.polynum number of polygons for each element
% w3d.trans transparency of each element
%
% Version / Date : 3.0 / 23-9-02
% removed triang optn & replaced face array Nan padding
% with 1st value padding to correct opengl display prob.
% Version / Date : 2.0 / 17-7-00
% changed output to a structure rather than separate arrays
% to use less memory.
% 1.0 / 21-6-99
% original version
%**********************************************************************************/
function [nel,w3d,infoline] = read_vrml(filename)
keynames=char('Coordinate3','point','coordIndex');
fp = fopen(filename,'r');
if fp == -1
fclose all;
str = sprintf('Cannot open file %s \n',filename);
errordlg(str);
error(str);
end
%* initialise arrays & counters */
fv = zeros(1,3);
foundkey=zeros(1,3); %* flags to determine if keywords found */
endpts=0; %/* flag set when end of co-ord pts reached for an element */
npt=0; %/* counter for num pts or conections */
npol=1; % counter for number of polygons in an element
nel=1; %/* counter for num of elements */
color(1,1:3) = [0.5 0.55 0.5]; % default color
maxnp = 0;
tempstr = ' ';
lastel = 1;
lnum = 1;
w3d(1).name = 'patch1';
infoline = '#';
trnsp(1) = 1; % transparency array - one val per element
%/* start of main loop for reading file line by line */
while ( tempstr ~= -1)
tempstr = fgets(fp); % -1 if eof
if tempstr(1) == '#' & lnum == 2,
infoline = tempstr;
end
lnum = lnum +1; % line counter
if ~isempty(findstr(tempstr,'DEF')) & ~endpts,
w3d(nel).name = sscanf(tempstr,'%*s %s %*s %*s');
end
if ~isempty(findstr(tempstr,'rgb')) | ~isempty(findstr(tempstr,'diffuseColor')) % get color data
sp = findstr(tempstr,'[');
if isempty(sp), sp = 12 + findstr(tempstr,'diffuseColor'); end
nc = 0;
if ~isempty(sp)
sp = sp +1;
[cvals,nc]=sscanf(tempstr(sp:length(tempstr)),'%f %f %f,');
end
if nc >= 3
if nel > lastel+1
for m = lastel+1:nel-1
color(m,1:3) = color(1,1:3); % if color not set then make equal to 1st
end
end
% if multi colors set then populate color matrix, this is an inventor feature
for s = 1:fix(nc/3)
color(s+nel-1,1:3) = cvals(3*s-2:3*s)';
lastel = s+nel-1;
end
end
end
if ~isempty(findstr(tempstr,'transparency')), % get transparency level
sp = findstr(tempstr,'trans');
[tvals,nc]=sscanf(tempstr(sp+12:length(tempstr)),'%f');
if nc > 0, trnsp(nel) = tvals(1); end
end
for i=1:3 %/* check for each keyword in line */
key = deblank(keynames(i,:));
if ~isempty(findstr(tempstr,key)) & isempty(findstr(tempstr,'#'))
%/* if key found again before all found there is a problem
% so reset flag for that key */
if ~foundkey(i), foundkey(i)=1;else foundkey(i)=0; end
if(i>1 & ~foundkey(i-1)) foundkey(i)=0; end %/* previous key must exist first ! */
end
end
if(foundkey(1) & foundkey(2)) %/* start of if A first 2 keys found */
if foundkey(3) %/* scan for connectivity data */
tempstr = [tempstr,' #']; %/* last word marker for end of line */
skip = '';
%/* loop puts integer values in a line into connection array */
word = ' ';
while(word(1) ~= '#')
format = sprintf('%s %%s#',skip);
[word,nw] = sscanf(tempstr,format);
skip = [skip,'%*s'];
[node,nred] = sscanf(word,'%d,');
if nred>0
for p = 1:nred
if node(p) ~= -1
npt = npt +1;
% increment node value as matlab counts from 1, vrml 0
w3d(nel).knx(npol,npt) = node(p)+1;
else
if npt > maxnp(nel), maxnp(nel) = npt; end
npt = 0;
npol = npol + 1;
end
end
end
end
if ~isempty(findstr(tempstr,']')) %/* End of data block marker */
polynum(nel)=npol-1; %/* store num of polygons in this element */
endpts=0; %/* reset flag ready for next element search */
npt=0;
npol=1;
foundkey = zeros(1,4); %/* reset keyword flags for next search */
nel = nel+1; %/* now looking for next element so increment counter
maxnp(nel) = 0;
w3d(nel).name = sprintf('patch%d',nel); % name next block
end
end %/* end of scan for connectivity */
%/* got 1st 2 keys but not 3rd and not end of co-ords data */
if(foundkey(2) & ~foundkey(3) & ~endpts) %/* scan for pts data */
sp = findstr(tempstr,'[');
if isempty(sp)
%/* points data in x y z columns */
[fv,nv]=sscanf(tempstr,'%f %f %f,');
else
%/* if block start marker [ in line - need to skip over it to data
% hence pointer to marker incremented */
sp = sp +1;
[fv,nv]=sscanf(tempstr(sp:length(tempstr)),'%f %f %f,');
end
if(nv>0)
if mod(nv,3) ~= 0
fclose(fp);
error('Error reading 3d wire co-ordinates: should be x y z, on each line');
end
nov = fix(nv/3);
for p = 1:nov
npt = npt+1;
w3d(nel).pts(npt,1:3)=fv(3*p-2:3*p);
end
end
if ~isempty(findstr(tempstr,']')) %/* end of pts data block */
endpts=1; %/* flag to stop entry to pts scan while reading connections */
npt=0;
end
end %/* end of scan for data pts */
end %/* end of if A */
end %/* end of main loop */
if nel == 0
fclose(fp);
error('Error reading 3d file: no data found');
end
nel = nel -1;
% if not same number of verticies in each polygon we need to fill
% out rest of row in array with 1st value
nc = size(color);
ts = size(trnsp);
for i = 1:nel
facs = w3d(i).knx;
ind1 = find(facs==0); [rown,coln] = ind2sub(size(facs),ind1);
facs(ind1) = facs(rown);
w3d(i).knx = facs;
if i > 1 & i > nc(1), color(i,1:3) = color(1,1:3); end % extend color array to cover all elements
w3d(i).color = color(i,1:3);
w3d(i).polynum = polynum(i);
if i > ts(2) | trnsp(i)==0,
trnsp(i) = 1;
end % extend transparency array to cover all elements
w3d(i).trans = trnsp(i);
end
fclose(fp);
% END OF FUNCTION read_vrml
%=====================================================================================
Here i have just replaced filename with sub1.wrl which is my vrml file.
It gives the following error
read_vrml
Error using read_vrml (line 31)
Not enough input arguments.
And if i edit ...function [nel,w3d,infoline] = read_vrml()
i.e to not enter anything only at the place of first occurrence of filename.
It gives error
read_vrml
Undefined variable "sub1" or class "sub1.wrl".
Error in read_vrml (line 31)
fp = fopen(sub1.wrl,'r');
I think you misunderstood the way functions are to be used.
Save the function into your matlab directory.
Then in your console/script call the function like this:
MySurf=read_vrml('sub1.wrl');
If you try to put your file name instead of the argument in the function definition, it will fail. Also, in Matlab, file names are arrays of characters (strings), you need to use quotation marks (') to identify a string.
SYNTAX-wise
fp = fopen( 'sub1.wrl', 'r' ); %% 'un-quoted' string was considered a variable
VRML-wise
The cleanest / the most straightforward would be to pre-process the .wrl file ( with a use of regex et al ) to retrieve the VRML-code decomposed [ x, y, z] data and to allow a pipe-line processing thereof

Matlab and Complex Number Computing

I am currently writing a code in matlab to analyze the optical flow in leach hearts and for some reason, whenever I run this it returns weird complex functions. I'm not sure where they come from and I would love some help on figuring that out.
function [opticalFlow] = opticalflowanalysis(handles,hOpticalflow)
videoReader = vision.VideoFileReader('jun07_0165_segment8to12_20.avi','ImageColorSpace','Intensity','VideoOutputDataType','single');
converter = vision.ImageDataTypeConverter;
opticalFlow = vision.OpticalFlow('OutputValue', 'Horizontal and vertical components in complex form','ReferenceFrameDelay', 6);
shapeInserter = vision.ShapeInserter('Shape','Lines','BorderColor','Custom', 'CustomBorderColor', 255);
videoPlayer = vision.VideoPlayer('Name','Motion Vector');
%Convert the image to single precision, then compute optical flow for the video. Generate coordinate points and draw lines to indicate flow.
i=0;
mm = ones(1080,1920);
%Display results.
while ~isDone(videoReader)
frame = step(videoReader);
im = step(converter, frame);
of = step(opticalFlow, im); %always complex number
aa = size(of)
lines = videooptflowlines(of, 5); %complex number only sometimes - when lines appear?
bb = size(lines)
x = i+ 1;
if(x==2)
mm = of;
end
% show diff bw of and lines matrices
if (x == 2)||(x == 10)
for j=1:1:1080 %gives j = [1 2 ... 720]
for k=1:1:1920 %gives k = [1 2 ... 1280]
of(j,k)
lines(j,k)
if(of(j,k) ~= lines(j,k))
disp(['of[',num2str(j),',',num2str(k),'] = ', num2str(of(j,k)), '...', 'lines[',num2str(j),',',num2str(k),'] = ', num2str(lines(j,k))])
end
end
end
end
if ~isempty(lines)
out = step(shapeInserter, im, lines);
step(videoPlayer, out);
end
end
%Close the video reader and player ,
%handles.output = hObject;
release(videoPlayer);
release(videoReader);
mm
It returns:
aa =
1080 1920
bb =
36465 4
Where do the variables from bb come from?
Thanks,
Jacob
Try putting semi-colons (ie ;) at the ends of the lines in which aa and bb are assigned to
aa = size(of);
...
bb = size(lines);
and see what happens.
Mind you, since neither aa nor bb seems to be used later in the program you could probably safely delete both those lines.

Avoid text overlap in MATLAB figures

When inserting text into MATLAB figures programmatically using text(x,y,'label'), I often find that the text blocks overlap, making them unreadable. I was wondering if there was any automated way to offset the text blocks so they wouldn't overlap. For instance, if I added 3 labels with top-left alignment at the points (0,0), (0.01,0), and (0.02,0), I'd want them to reposition themselves like:
. . .
label1
label2
label3
whereas currently they look like:
. . .
la~~~~~~l3
where the squiggles are unreadable due to the overlap.
If there's not already a way to do this, I could roll my own algorithm/heuristic for the task, but is there a way to query a figure (or the gcf handle) for the bounding boxes of all existing text boxes on it? So then I can call this every time I want to place a label?
Thanks!
Here's a solution I came up with... seems to work OK.
function h = textfit(x,y,txt,varargin)
% textfit(x,y,txt,varargin)
%
% Mike Lawrence 2011
ythresh = 0.4; % maximal allowable overlap (includes cell padding accounted for in "extent" property)
xthresh = 0.1;
n = length(x);
if ~iscell(txt), txt={txt}; end
if length(y)~=n || length(txt)~=n, error('length mismatch between x,y,txt'); end
h = text(x,y,txt,varargin{:});
yl=ylim; ytot=diff(yl);
xl=xlim; xtot=diff(xl);
maxtries = 100;
for t=1:maxtries
ext = nan(n,4);
for i=1:n, ext(i,:) = get(h(i),'extent'); end
xstart=ext(:,1); xsz=ext(:,3); xend=xstart+xsz;
ystart=ext(:,2); ysz=ext(:,4); yend=ystart+ysz;
overlapx = zeros(n,n);
overlapy = zeros(n,n);
for i1=1:n-1, for i2=i1+1:n
if xstart(i1)<=xend(i2)&xstart(i2)<=xend(i1)
overlapx(i1,i2)=(min(xend(i2)-xstart(i1),xend(i1)-xstart(i2)))/(min(xsz(i1),xsz(i2)));
end
if ystart(i1)<=yend(i2)&ystart(i2)<=yend(i1)
overlapy(i1,i2)=(min(yend(i2)-ystart(i1),yend(i1)-ystart(i2)))/(min(ysz(i1),ysz(i2)));
end
end,end
overlapmax = max(overlapx,overlapy);
ov = (overlapx>xthresh & overlapy>ythresh);
[o1 o2] = find(ov);
if isempty(o1), break; end
[tmp ord] = sort(overlapmax(find(ov)));
o1=o1(ord); o2=o2(ord);
moved = false(n,1);
for i=1:length(o1), i1=o1(i); i2=o2(i);
if moved(i1) || moved(i2), continue; end
pos1 = get(h(i1),'position');
pos2 = get(h(i2),'position');
oy = overlapy(i1,i2)*min(ysz(i1),ysz(i2));
ox = overlapx(i1,i2)*min(xsz(i1),xsz(i2));
if oy/ytot < ox/xtot % overlapy is easier to fix
shift = 0.5*(1-ythresh)*oy;
if ystart(i1)<ystart(i2) % i1 above i2
pos1(2)=pos1(2)-shift; pos2(2)=pos2(2)+shift;
else % i1 below i2
pos1(2)=pos1(2)+shift; pos2(2)=pos2(2)-shift;
end
else % overlapx is easier to fix
shift = 0.5*(1-xthresh)*ox;
if xstart(i1)<xstart(i2) % i1 left of i2
pos1(1)=pos1(1)-shift; pos2(1)=pos2(1)+shift;
else % i1 right of i2
pos1(1)=pos1(1)+shift; pos2(1)=pos2(1)-shift;
end
end
set(h(i1),'position',pos1);
set(h(i2),'position',pos2);
moved([i1 i2]) = true;
end
end
if nargout==0, clear h, end