フィルターのクリア

Move Line on an Image with Up and Down Arrow

3 ビュー (過去 30 日間)
Enea Baumann
Enea Baumann 2018 年 4 月 18 日
コメント済み: Jan 2018 年 4 月 21 日
Hi Everyone
I have a series of pictures which i want to process with Matlab. I should be able to open the first image, then move a line up and downwards with the up and down arrow and finally change to next picture with return.
I was able to define a callback function which registers the keyboard actions.
If I press the uparrow it adds 1 to a variable s.
If I press the downarrow it subtracts 1 from a variable s.
If I press return it adds 1 to a variable k.
function y = KeyPressCb(~,evnt)
fprintf('%s\n',evnt.Key);
global s
global k
if strcmp(evnt.Key,'uparrow')==1
s=s+1;
elseif strcmp(evnt.Key, 'downarrow')==1
s=s-1;
elseif strcmp(evnt.Key, 'return')==1
k = k + 1;
end
end
Now I want to return this values to the main program, so that i can use this two variables (k and s) to change the line coordinates and the image array counter. How do i do that?
Is there an other, easier way to do it?
Greetings
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 4 月 21 日
We are not free private consulting. The "price" we ask is that the questions and responses are public for everyone to learn from. When someone edits away a question after it has been answered, the volunteers tend to feel as if they have been taken advantage of.
Jan
Jan 2018 年 4 月 21 日
@Wunman Usam: Please do not remove the contents of your question after an answer has been given. This is considered to be impolite, because the nature of this forum is to share solutions in public. If you delete the question afterwards, the time spent for posting an answer is lost for the community.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2018 年 4 月 18 日
  3 件のコメント
Walter Roberson
Walter Roberson 2018 年 4 月 19 日
function driver
y = 0; %shared variable
ax = gca;
fig = ancestor(ax, 'figure');
plot( ax, randn(1,50) * 10 );
XL = get(ax, 'XLim');
hold(ax, 'on')
h = plot(ax, XL, [y y]);
hold(ax, 'off');
set(fig, 'WindowKeyPressFcn', @KeyPressCb);
function KeyPressCb(~,evnt)
if strcmp(evnt.Key,'uparrow')
fprintf('up!\n');
y = y + 1;
set(h, 'YData', [y y]);
elseif strcmp(evnt.Key, 'downarrow')
fprintf('down!\n');
y = y - 1;
set(h, 'YData', [y y]);
end
end
end
Enea Baumann
Enea Baumann 2018 年 4 月 19 日
Wow! Thank you so much!!!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by