trying to convert IDL codes to MATLAB
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
dpb
2017 年 8 月 9 日
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.
採用された回答
Kris Fedorenko
2017 年 8 月 11 日
編集済み: Kris Fedorenko
2017 年 8 月 11 日
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 件のコメント
Kris Fedorenko
2017 年 8 月 25 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!