how do i shift my movmean function by y=mx+c to adjust for data creep - matlab-figure

This is the code:
subplot(3,1,1);
plot(Fz(500:1200000),'Color','k');
hold on
M1 = movmean(Fz(500:1200000),[2000,2000]);
plot(M1,'Color','r')
Any ideas on how to shift my movmean function by y=mx+c to adjust for data creep?

Related

Quick explanation, what is code behind $ in regards to x and y? (very short example using AutoIt)

Being new to programming, AutoIt using Imagesearch
$result = _ImageSearch("flowr.png",1,$x1,$y1,100)
having saved the desired imagine, what does
the 1 after the image-name mean?
(1 click) $x1 and $y1 mean
(coordinates for that 1x click) the 100 the speed?
The line of code began with
#include <ImageSearch.au3>
$x1=0
$y1=0
what is the $x1=0 here?
I'd love to just use google and type in "what does $x1=0 mean" but the translation of it yields a completely different answer and has nothing to do with coding^^
Thank you very much for clarifying!
The 1 after the flowername seems to be the tolerance, a value from 0-255 according to this documentation I found here
; Description: Find the position of an image on the desktop
; Syntax: _ImageSearchArea, _ImageSearch
; Parameter(s):
; $findImage - the image to locate on the desktop
; $tolerance - 0 for no tolerance (0-255). Needed when colors of
; image differ from desktop. e.g GIF
; $resultPosition - Set where the returned x,y location of the image is.
; 1 for centre of image, 0 for top left of image
; $x $y - Return the x and y location of the image
;
; Return Value(s): On Success - Returns 1
; On Failure - Returns 0
The lines like $x1 = 0 are simple assignment operations. You are saving the value 0 in the variable $x1. You can later add, subtract, multiply, etc. using that value or store some other calculation which makes your program easy to alter.
You should try some examples to get the basics of programming down before diving in to an image search program. If all else fails though you can always check the Documentation.

Plotting image and points on Matlab GUI via update function

excuse my noobness, but this is my first post.
i generated this gui in matlab, and i want to plot an image on one of the axis from an update function.
i know in Matlab you can just do something like
image(img)
hold on
plot(x1,z1)
hold off
but how can one do this with the gui?
here is a segment of the update function
%get a handle to the GUI's 'current state' window
deflectionx = findobj('Tag','deflectionx_display');
deflectiony = findobj('Tag','deflectiony_display');
depth = findobj('Tag','depth_display');
Graph = findobj('Tag','Graphical_display');
UltraS = findobj('Tag','UltraS_image');
%update the gui
set(deflectionx,'String',x_def);
set(deflectiony,'String',y_def);
set(depth,'String',insert_depth);
%% above works fine. below does not
%i want this to plot those points on top of the image in the large graph panel of the gui
plot(Graph,img1)
hold on
plot(Graph,x1,z1);
hold off
%this should plot the second image on the UltraS panel
plot(UltraS,img2)
Please and thanks in advance!
So figured it i had to write the handles of the GUI to the workspace in the opening function of the gui
% --- Executes just before VR_gui is made visible.
function VR_gui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to VR_gui (see VARARGIN)
% Choose default command line output for VR_gui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
%setting axis
needle_plot = handles.Graphical_display;
US_plot = handles.US_image;
%write handle to workspace
assignin ('base','needle_plot',needle_plot);
assignin ('base','US_plot',US_plot);
then read the workspace variables from the update function
needle_plot = evalin('base','needle_plot');
US_plot = evalin('base','US_plot');
axes(US_plot);
image(img2);
axes(needle_plot);
plot(x1,z1,'r--o');

Matlab show image in gui

I have been trying to show an image after browsing it. However, I have been getting errors like:
??? Reference to non-existent field 'axes1'.
Error in ==> ImGui>Browse_Callback at 19
axes(handles.axes1)
??? Error while evaluating uicontrol Callback
I have tried working with both predefined axes [like 'axes(handles.axes1);'] as well as with post-defined [like 'imshow(imgorg, 'Parent', handles.axes1);']. Unfortunately, both techniques have not worked out for me and I am consistently stuck with axes. I also tried making a customized axes and work with that but it also failed to show my image on the figure. Can anyone please identify/ rectify the problem in my code:
function ImGui
f =figure('Visible','on','Position',[460,200,700,385]);
BrowseBt = uicontrol('Style','pushbutton',...
'String','Browse','Position',[600,350,70,25],...
'Callback',#Browse_Callback);
dispnames = uicontrol('Style','text','String','',...
'Position',[50,350,400,20]);
movegui(f,'center');
function Browse_Callback(hObject, eventdata, handles)
handles.output = hObject;
[FileName,PathName] = uigetfile('*.jpg;*.png','Select an image file',...
'C:\Users\owner\Downloads\Conjunctiva\SGRH');
fpname = strcat(PathName,FileName);
dispnames = uicontrol('Style','text','String',fpname,...
'Position',[50,350,400,20]);
imgorg = imread(fpname);
handles.output = hObject;
guidata(hObject, handles);
axes(handles.axes1);
imshow(imgorg);
% ImAxes = axes('Parent', f, ...
% 'Units', 'normalized', ...
% 'position',[50 50 400 250]);
% 'HandleVisibility','callback', ...
% imshow(imgorg, 'Parent', handles.axes1);
% imshow(imgorg, 'Parent', handles.ImAxes);
end
end
Use the guidata function.
and reorganize your code a little bit
You define all your uicontrols (button, textbox, axes etc ...) and you assign their handle to a structure (called handles here). Then when you GUI is fully defined, call guidata to store this handle structure in a place where any callback can access it.
Then in your callback function, call guidata again to retrieve this handle structure and get access to your objects (you axes and your textbox).
function ImGui
f =figure('Visible','on','Position',[460,200,700,385]);
handles.BrowseBt = uicontrol('Style','pushbutton',...
'String','Browse','Position',[600,350,70,25],...
'Callback',#Browse_Callback);
handles.dispnames = uicontrol('Style','text','String','',...
'Position',[50,350,400,20]);
handles.ImAxes = axes('Parent', f, ...
'Units', 'pixels', ...
'position',[30 30 640 300],...
'visible','off');
movegui(f,'center');
guidata(f,handles) ;
function Browse_Callback(hObject, eventdata)
handles = guidata(hObject);
[FileName,PathName] = uigetfile('*.jpg;*.png','Select an image file');
fpname = strcat(PathName,FileName);
imgorg = imread(fpname);
set(handles.dispnames,'String',FileName)
set(handles.ImAxes,'visible','on') ;
imshow(imgorg, 'Parent', handles.ImAxes);
guidata(hObject, handles);
end
end
In this specific case you don't really need to call guidata again at the end of the callback to store the values again but it is good practice, in case you modified something you want the changes to be saved.

Switch scrolling direction with shortkey

I currently have an AHK script which switches the scrolling direction of my mouse.
WheelUp::
Send {WheelDown}
Return
WheelDown::
Send {WheelUp}
Return
My colleagues don't like this and use my computer sometimes.
How can I assign a shortkey to switch the scrolling direction?
What I want:
When I press win+z the scrolling direction is changed, when I pres win+z again, the scrolling direction is changed back.
So basically the scrolling direction can be changed when pressing win+z
Is that possible with AHK?
Yes you can modify your hotkeys to have more code.
You will have to use if statements and variables.
Example:
global direction := 1
^s:: ; ctrl + s will launch this code you can modify this to win + z
direction := Mod( direction + 1 , 2 ) ; alternates values of direction between 1 and 0
return
WheelUp::
if(direction)
Send {WheelDown}
else
Send {WheelUp}
Return
; and reverse for wheeldown

Matlab GUI: How to Save the Results of Functions (states of application)

I would like to create an animation which enables the user to go backward and forward through the steps of simulation.
An animation has to simulate the iterative process of channel decoding (a receiver receives a block of bits, performs an operation and then checks if the block corresponds to parity rules. If the block doesn't correspond the operation is performed again and the process finally ends when the code corresponds to a given rules).
I have written the functions which perform the decoding process and return a m x n x i matrix where m x n is the block of data and i is the iteration index. So if it takes 3 iterations to decode the data the function returns a m x n x 3 matrix with each step is stired.
In the GUI (.fig file) I put a "decode" button which runs the method for decoding and there are buttons "back" and "forward" which have to enable the user to switch between the data of recorded steps.
I have stored the "decodedData" matrix and currentStep value as a global variable so by clicking "forward" and "next" buttons the indices have to change and point to appropriate step states.
When I tried to debug the application the method returned the decoded data but when I tried to click "back" and "next" the decoded data appeared not to be declared.
Does anyone know how is it possible to access (or store) the results of the functions in order to enable the described logic which I want to implement in Matlab GUI?
Ultimately, this is a scoping of variables problem.
Global variables is rarely the right answer.
This video discusses the handles structure in GUIDE:
http://blogs.mathworks.com/videos/2008/04/17/advanced-matlab-handles-and-other-inputs-to-guide-callbacks/
This video discusses sharing of variables between GUIs and could apply to a single GUI problem also.
http://blogs.mathworks.com/videos/2005/10/03/guide-video-part-two/
The trick is to use nested functions so that they share the same workspace. Since I already started with an example in your last question, now I'm simply adding GUI controls to enable going forward/backward interactively, in addition to play/stop the animation:
function testAnimationGUI()
%# coordinates
t = (0:.01:2*pi)'; %# 'fix SO syntax highlight
D = [cos(t) -sin(t)];
%# setup a figure and axis
hFig = figure('Backingstore','off', 'DoubleBuffer','on');
hAx = axes('Parent',hFig, 'XLim',[-1 1], 'YLim',[-1 1], ...
'Drawmode','fast', 'NextPlot','add');
axis(hAx, 'off','square')
%# draw circular path
line(D(:,1), D(:,2), 'Color',[.3 .3 .3], 'LineWidth',1);
%# initialize point
hLine = line('XData',D(1,1), 'YData',D(1,2), 'EraseMode','xor', ...
'Color','r', 'marker','.', 'MarkerSize',50);
%# init text
hTxt = text(0, 0, num2str(t(1)), 'FontSize',12, 'EraseMode','xor');
i=0;
animation = false;
hBeginButton = uicontrol('Parent',hFig, 'Position',[1 1 30 20], ...
'String','<<', 'Callback',#beginButton_callback);
hPrevButton = uicontrol('Parent',hFig, 'Position',[30 1 30 20], ...
'String','<', 'Callback',#previousButton_callback);
hNextButton = uicontrol('Parent',hFig, 'Position',[60 1 30 20], ...
'String','>', 'Callback',#nextButton_callback);
hEndButton = uicontrol('Parent',hFig, 'Position',[90 1 30 20], ...
'String','>>', 'Callback',#endButton_callback);
hSlider = uicontrol('Parent',hFig, 'Style','slider', 'Value',1, 'Min',1,...
'Max',numel(t), 'SliderStep', [10 100]./numel(t), ...
'Position',[150 1 300 20], 'Callback',#slider_callback);
hPlayButton = uicontrol('Parent',hFig, 'Position',[500 1 30 20], ...
'String','|>', 'Callback',#playButton_callback);
hStopButton = uicontrol('Parent',hFig, 'Position',[530 1 30 20], ...
'String','#', 'Callback',#stopButton_callback);
%#----------- NESTED CALLBACK FUNCTIONS -----------------
function beginButton_callback(hObj,eventdata)
updateCircle(1)
end
function endButton_callback(hObj,eventdata)
updateCircle(numel(t))
end
function nextButton_callback(hObj,eventdata)
i = i+1;
if ( i > numel(t) ), i = 1; end
updateCircle(i)
end
function previousButton_callback(hObj,eventdata)
i = i-1;
if ( i < 1 ), i = numel(t); end
updateCircle(i)
end
function slider_callback(hObj, eventdata)
i = round( get(gcbo,'Value') );
updateCircle(i)
end
function playButton_callback(hObj, eventdata)
animation = true;
while animation
i = i+1;
if ( i > numel(t) ), i = 1; end
updateCircle(i)
end
end
function stopButton_callback(hObj, eventdata)
animation = false;
end
function updateCircle(idx)
set(hSlider, 'Value', rem(idx-1,numel(t))+1) %# update slider to match
set(hLine,'XData',D(idx,1), 'YData',D(idx,2)) %# update X/Y data
set(hTxt,'String',num2str(t(idx))) %# update angle text
drawnow %# force refresh
if ~ishandle(hAx), return; end %# check valid handle
end
%#-------------------------------------------------------
end
You might find the slider functionality a bit buggy, but you get the idea :)

Resources