Changing psychtoolbox screen - matlab

I am using Psychtoolbox to display on a screen as part of an interface. I create a blank screen with [win,Rect]=Screen('OpenWIndow',etc.etc...) in my main script. I would like to use a function call later on in the script to update the screen, but I have no idea how to get the values in and out of the function to change the Screen.
So something like:
%main script
[win,Rect]=Screen('OpenWIndow',0,[0 0 0],[0 0 1280 1024]);
%do other processing (in my case communicating with another computer.)
DrawStuff() %function that takes variables from script and updates the screen
% continue script

Screen('Flip',win) is what you are looking for, but you need to issue some drawing commands for it to show anything.
Please read the file PsychDocumentation/PTBTutorial-ECVP2013.pdf in the psychtoolbox distribution to understand the basics of stimulus presentation.

Related

MATLAB-SIMULINK GUI interaction

I am trying to create a MATLAB GUI that will display the result of an ADC in SIMULINK. Here is a picture of the setup I have in Simulink. I use a Display block to output the ADC. I want the value of the Display block be passed to a label I have in my GUI. I use the code:
get_param('Simulink_ModelSim/Power1','value')
but an error appears. I don't understand what is happening. When I pass 1 bit with a switch, it goes well. but with displays it does not. Please Help. TIA

Why does Matlab set the background white when saving a scope printed to figure?

I want to programmatically 'Print to figure' a Simulink scope and save the resulting figure to a folder.
Consider following Simulink model and select the scope:
I run following code (inspired by this question):
scopeName=get_param(gcb,'Name');
hs=findall(0,'Name',scopeName);
hf=figure(1);
hp=findobj(hs.UserData.Parent,'Tag','VisualizationPanel');
copyobj(hp,hf)
filename='test.tiff';
print('-dtiff',filename);
Although both the scope and the figure have a black background
the saved file has a white background
Is there something wrong with the print command or with something else?
By default, MATLAB inverts the background colors when printing to a figure. To get around this, you can set the InvertHardCopy to 'off'
set(gcf, 'InvertHardCopy', 'off')
Doing this (as opposed to using getframe) results in a much higher resolution image as getframe simply saves the figure at screen resolution (72dpi).
Another option is to use export_fig from the MATLAB file exchange to save the figure which will more reliably reproduce the image that is on your screen.
You can get the same view as you see:
img = getframe(gcf);
imwrite(img.cdata,'test.tiff');

how to save figure of gui plot which will run on a computer that does not have matlab

I have made a Gui program that I compile to EXE application which lots csv file into graph data. I buit a save button but I do not know how save figure with different name each time cause (savefig anduisave both uses matlab program). I am posting my code below if anyoff you guys figure out how to save gui figue into image or anything that does require matlab to open. Last function is the callback function for save button.
function ma_Callback(hObject, eventdata, handles)
% i tried uisave but not possible to run computer without matlab cause mcr
% does not run uisave
% i tried copyopbj but since i did not put a name on my figure it did not
% work
%savefig
If you are trying to save a kind of image from your figure, then the best option which supports many aspects, is using print function.
I have already done this in a compiled app and it works perfect. Using print function you can set different file type(vector formats like *.svg are also supported), resolution(dpi), and so many others.
Although you can use print function directly on the figure, but I found that the best way (More Customization like removing or adding some objects and changing many options) is to follow this steps:
Create another figure with Visible='on' but a position that is out of screen with the same width and height of Main Figure.
normalized position = [-1, -1, ?, ?]. (Create this figure in start up and don't destroy it until your app exits, let call it Print Figure).
Copy your figure content (or the parts you are interested in) using copyobj to that figure (you may need to set Parent property of some key objects like panels to this new figure). They would look exactly as they look in the main figure, because they have the same properties. you can add or remove some objects in this step.
Change aspect ratio of "Print Figure" for a better output.
Print this figure with all options (file format, dpi, ...) you need. in my own GUI i allowed the user to change this settings with an input dialog.
In my app i used functions like winopen to show the output, and output directory to the user, when the print task was done. Print process takes some time, specially if dpi is huge, so it is also a good idea to inactivate buttons and show wait cursor.
Update:
a simple usage would be:
print(MainFigure, 'myFileName', '-dpng', '-r300')

why would Matlab skip the loop?

I have a question that I can seem to wrap my head around,
I have created a gui that uses the unput from the user to run a script within the gui and later display the results to the user interface. What I dont understand is that everything is running ok until I choose one particular file. The interesting and mind boggling is that the script jumps a nested loop (whie this dosent happen for the other choices). I dont understand why this happens and cant find anything relavent on the internet. The script stand alone executes perfectly.
for i=2:length(Data_last_values)
for j=2:length(temp_nov)
if Data_last_values(i,4)>temp_nov(j,1) & Data_last_values(i,4)<temp_nov(j-1,1)
Data_last_values(i,9)=Data_last_values(i,3)+Q_leak_dot(j);
disp('gone through loop')
end
end
end
displayed above is the part of the nested loop that matlab chooses to skip. would any one know why this happens? below I present the gui script:
if not(isempty(cell2mat(z)))
run Daughter
assignin('base','avg',data(:,8))
axes(handles.axes1);
markerSize = 50;
scatter(Data_last_values(:,4),Data_last_values(:,9),markerSize,Data_last_values(:,5)) % -> volumetric mass flow is used in the color bar
colormap(jet(20));
h=colorbar;
xlabel('T_{water}[C]')
ylabel('Q_{out} [W]')
ylabel(h, 'Volumetric Flow [Lt/min]')
grid minor
myvar = evalin('base', 'avg');
y=line([0 max(Data_last_values(:,4))], [mean(myvar) mean(myvar)]);
xlim([0 max(Data_last_values(:,4))])

how to position Matlab GUI window at top of screen?

I used Matlab GUIDE to create a GUI.
It is displayed mid-screen.
How can I position it at the top of the screen; so that the top edge of the GUI window is at top of screen.
It will be used on different Windows 7 computers with different screen resolutions.
I tried to set hObject.Position(2) but it doesn't do what I want.
I think the simplest way would be to use movegui in the OpeningFcn of your GUI with the appropriate argument, i.e. using either 'north', 'northeast' or 'northwest'.
The calling syntax is quite simple, using the handles to the figure created. In GUIDE, the default name for figures is "figure1", so in your case the code would look like this (unless you changed the figure's name):
movegui(handles.figure1,'northwest') %// or whatever
Note that movegui calls the following 3 functions to get the screen size and monitor positions/units:
screensize = get(0, 'ScreenSize');
monitors = get(0,'MonitorPositions');
old0units = get(0, 'Units');
So you could do the same to make the calculations yourself in order to place the figure precisely where you want if the above solution is not sufficient for you.