How do I execute this script as a function?

조회 수: 2 (최근 30일)
stephen abineri
stephen abineri 2015년 3월 11일
댓글: Adam 2015년 3월 11일
My group and I are currently adding to an open source piece called IR-view. We have added a push button to its control panel and we are trying to put some functionality to it. The current control panel allows us to extract frames from an uploaded RAW file in the form of a 3D matrix. We have written a short script that extracts the highest numerical value from each frame and plots each of these high points on a graph. The script by itself works fine. My question is how do I execute this script from the push button? I have tried using callback and I tried making the script using a function but I am getting an error that says "To many input arguments". This is what we have:
for i=1:frames
frame = allf(:,:,i);
largest(i) = max(frame(:));
[num idx]= max(frame(:));
[row column]= ind2sub (size(frame),idx);
locationx(i)=row;
locationy(i)=column;
end
figure (1)
scatter(locationy,locationx)
set(gca,'YDir','reverse')
Where 'allf' is what we rename the matrix when we extract it. frames refers to the amount of frames in the RAW file (in this case its 50). The script as you see it works fine. But it needs to run from a push button.
Many thanks

답변 (2개)

Adam
Adam 2015년 3월 11일
편집: Adam 2015년 3월 11일
set( hPushButton, 'Callback', @(src,evt) func( allf ) )
where you create the pushbutton (obviously you can just add it to the construction of the uicontrol too). Then create the following somewhere on your path:
function func( allf )
for i=1:frames
frame = allf(:,:,i);
largest(i) = max(frame(:));
[num idx]= max(frame(:));
[row column]= ind2sub (size(frame),idx);
locationx(i)=row;
locationy(i)=column;
end
figure (1)
scatter(locationy,locationx)
set(gca,'YDir','reverse')
should do the trick. Obviously use a sensible function name though!
  댓글 수: 4
stephen abineri
stephen abineri 2015년 3월 11일
thanks, yes they all finish with 'end' and I changed this so that it does as well. I even retyped the code by hand but still get the same problem.
Adam
Adam 2015년 3월 11일
I can't see any obvious reason why that would be the case. Have you tried leaving it where it was when it was a script and just adding the function line at the top of the file to turn it into a function there?

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2015년 3월 11일
If you're using GUIDE, just call the function from within the button's callback function. Let's say your function is called FindMax() and it takes allf and frames as input arguments. Then call it in the callback function like this
[x, y] = FindMax(allf, frames);
Then define it like
function [locationx, locationy] = FindMax(allf, frames)
% The code goes here.
By the way, is there any reason why you're defining locationx as the row instead of the column and locationy as the column instead of the row? Usually x is the horizontal distance and y is the vertical distance and you're swapping and going against the convention for some reason.
  댓글 수: 2
stephen abineri
stephen abineri 2015년 3월 11일
thanks, I will try this. Yes the axis get inverted in the image, in Ir view the image is upside down if the axis is not inverted.
Image Analyst
Image Analyst 2015년 3월 11일
It's not getting inverted. It's getting transposed. There is a BIG difference. But since you're doing scatter(locationy,locationx) and swapping x and y you're not noticing the difference.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by