trying to convert IDL codes to MATLAB
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
hasan alhussaini
il 8 Ago 2017
Commentato: Kris Fedorenko
il 25 Ago 2017
Hi i'm trying to create a similiar code on matlab to the one i have in IDL
Basically the code lets you select a box_cursor over a region of an image or select the x,y,nx,ny deminsions
the IDL codes are
roichox:
print,'PLEASE SELECT YOUR REGION OF INTEREST: 1=box, 2= enter values'
read,roichoice
case roichoice of
1: begin
box_cursor,x,y,nx,ny
print,"Margins and dimensions:",x,y,nx,ny
end
2: begin
print, 'x?'
read,x
;print, 'y?'
;read,y
print, 'nx?'
read,nx
;print,'ny?'
;read,ny
end
else: goto, roichox
endcase
my translation so far is
roichoice=input('PLEASE SELECT YOUR REGION OF INTEREST: 1=box, 2= enter values\n');
switch( roichoice)
case 1
[I ,rect]=imcrop();
yb=rect(1);
xb=rect(2);
nyb=rect(3);
nxb=rect(4);
fprintf('Margins and dimensions: x=%f y=%f nx=%f ny=%f',xb,yb,nxb,nyb);
case 2
xb=input('x?');
nxb=input( 'nx?');
otherwise
goto(roichox);
return
end
2 Commenti
dpb
il 9 Ago 2017
As John says, there is no GOTO in Matlab; leave the otherwise clause empty and enclose the block in a while loop. Use break when get a valid response to exit the block and go on to next step.
Risposta accettata
Kris Fedorenko
il 11 Ago 2017
Modificato: Kris Fedorenko
il 11 Ago 2017
As dpb said above, you can use a while loop instead of "goto", which does not exist in MATLAB. Here is one possible example of how you can make it work:
roichoice=input('PLEASE SELECT YOUR REGION OF INTEREST: 1=box, 2= enter values\n');
while ~((roichoice == 1) || (roichoice == 2))
disp('You must enter either 1 or 2')
roichoice=input('PLEASE SELECT YOUR REGION OF INTEREST: 1=box, 2= enter values\n');
end
switch( roichoice)
case 1
[I ,rect]=imcrop();
yb=rect(1);
xb=rect(2);
nyb=rect(3);
nxb=rect(4);
fprintf('Margins and dimensions: x=%f y=%f nx=%f ny=%f',xb,yb,nxb,nyb);
case 2
xb=input('x?');
nxb=input( 'nx?');
end
Hope this helps! And YAY for switching from IDL :)
2 Commenti
Kris Fedorenko
il 25 Ago 2017
Hi Hasan,
The difference would be in what these functions return:
- imrect returns a handle to an imrect object. Based on the documentation, you can get the x,y position and dimensions by using a "getPosition" function. For example:
rectHandle=imrect();
rect = getPosition(rectHandle);
where rect(1) is x position, rect(2) is y position, rect(3) is width, and rect(4) is height.
- rbbox returns a four-element vector, [x y width height], where x and y are the x and y components of the lower left corner of the box, and width and height are the dimensions of the box. But rbbox returns immediately if a button is not currently pressed. You can use rbbox with waitforbuttonpress, so that rbbox returns when you release the mouse button:
waitforbuttonpress
rect = rbbox();
Another difference is that rbboc would define the box in the coordinates of the figure rather than in the axes coordinates.
Hope this helps!
Kris
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!