I'm running psychtoolbox-3.0.10 in MATLAB R2011B in a Windows XP partition in a Macbook computer. I've been trying to run a script a Matlab for behavioral sciences course (see here. The file is called FunkyScreen.m.
It works for first 30 seconds (the first 80 lines or so) and then Matlab suddenly crashes and closes. I clicked on the 'details' button of the message and it shows me that the program probably stopped because of the mex files.
Questions:
Should I manually setup Matlab to compile those files?
Or is it just crashing because of internal problems?
The script is:
% FunkyScreen.m
%
% opens a window using psychtoolbox,
% makes the window do some funky things
%
% written for Psychtoolbox 3 on the PC by IF 3/2007
screenNum=0;
flipSpd=13;% a flip every 13 frames
[wPtr,rect]=Screen('OpenWindow',screenNum);
monitorFlipInterval=Screen('GetFlipInterval', wPtr);
% 1/monitorFlipInterval is the frame rate of the monitor
black=BlackIndex(wPtr);
white=WhiteIndex(wPtr);
% blank the Screen and wait a second
Screen('FillRect',wPtr,black);
Screen(wPtr,'Flip');
HideCursor;
tic
while toc<1;
end
% make a rectangle in the middle of the screen flip colors and size
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr,'Flip');% collect the time for the first flip with vbl
for i=1:10
Screen('FillRect',wPtr,[0 0 255], [100 150 200 250]);
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
% flip 13 frames after vbl
Screen('FillRect',wPtr,[255 0 0], [100 150 400 450]);
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
end
% blank the screen and wait a second
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr,'Flip', vbl+(flipSpd*monitorFlipInterval));
tic
while toc<1;
end
% make circles flip colors & size
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr,'Flip');
for i=1:10
Screen('FillOval',wPtr,[0 180 255], [ 500 500 600 600]);
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
Screen('FillOval',wPtr,[0 255 0], [ 400 400 900 700]);
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
end
% blank the Screen and wait a second
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr,'Flip', vbl+(flipSpd*monitorFlipInterval));
tic
while toc<1;
end
% make lines that flip colors size & position
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr,'Flip');
for i=1:10
Screen('DrawLine',wPtr,[0 255 255], 500, 200, 700 ,600, 5);
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
Screen('DrawLine',wPtr,[255 255 0], 100, 600, 600 ,100, 5);
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
end
% blank the Screen and wait a second
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr,'Flip', vbl+(flipSpd*monitorFlipInterval));
tic
while toc<1;
end
% combine the stimuli
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr,'Flip');
for i=1:10
Screen('FillRect',wPtr,[0 0 255], [100 150 200 250]);
Screen('DrawLine',wPtr,[0 255 255], 500, 200, 700 ,600, 5);
Screen('FillOval',wPtr,[0 180 255], [ 500 500 600 600]);
Screen('TextSize', wPtr , 150);
Screen('DrawText', wPtr, 'FUNKY!!', 200, 20, [255 50 255]);
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
Screen('FillRect',wPtr,[255 0 0], [100 150 400 450]);
Screen('FillOval',wPtr,[0 255 0], [ 400 400 900 700]);
Screen('DrawLine',wPtr,[255 255 0], 100, 600, 600 ,100, 5);
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
end
% blank the screen and wait a second
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr,'Flip', vbl+(flipSpd*monitorFlipInterval));
tic
while toc<1;
end
Screen('CloseAll');
ShowCursor
Here is how you can (probably) eliminate the problem.
Step 1: Run the code, try to get an indication of where it crashes
Step 2: Possibly using the information from Step 1, devide your code in 2 halves.
Step 3: Run both halves separately, see which one crashes
Step 4: Keep repeating the steps above untill you have identified the culprit
Step 5: Try to deal with the specific problem that is found
Related
I have been trying to put my graphic axis in log2 scale but something quite odd appears on the figure. The first data 63 appears at the beggining and the end of the x-scale and for some reason the first point does not appear. Also the points are not exactly centered on the x-ticks... do you have any idea why ?
Thanks in advance for you help !!!
clear all; clc;
%% Vectors
freq=[63 125 250 500 1000 2000 4000 8000 16000]
logfreq=log2(freq);
Lp1=[93.9 93.9 93.8 93.8 93.8 93.6 93.3 91.8 87.8]
Lp2=[93.9 93.9 93.8 93.8 94 94.1 94.4 94.6 95.3]
Lp3=[93.9 93.9 93.9 93.8 94.1 94.4 95.2 97.2 100.9]
%% Plot
figure
plot(log2(freq),Lp1,'+-','linewidth',1.7)
hold on; grid on;
plot(log2(freq),Lp2,'+-','linewidth',1.7)
plot(log2(freq),Lp3,'+-','linewidth',1.7)
set(gca,'fontsize',20)
set (gca, 'XTickLabel', logfreq);
set(gca,'XTickLabel',
{'63','125','250','500','1000','2000','4000','8000','16000'})
xlabel('Frequency [Hz]','fontsize',20)
ylabel('Pressure Level [dB]','fontsize',20)
leg=legend({'Sin correcion','Campo libre','Incidencia aleatoria'},'fontsize',18)
And here is the figure :
You want
set(gca,'XTick',logfreq);
instead of set(gca,'XTickLabel',logfreq)
With your incorrect code, the 63 appears at the start and the end because there are (incorrectly) 10 x tick locations but you are specifying only 9 labels, and hence the first one is repeated. (If you'd only specified 8 then the first 2 would be repeated, etc.)
I am plotting trajectories in Matlab using contourf. I am having an issue with the colors matching the data. I have posted my current image below. All areas that do not have data should be white as they are zero which I specifically specified in the script(they are currently blue-ish which is the the 0.1 to 1 range). In addition, values that are yellow, should be in the blue range(<1). Any suggestions?
Here is the part of my script where I do the plotting:
axesm('mercator', 'MapLatLim', latlim, 'MapLonLim', lonlim,...
'Frame', 'on', 'Grid', 'on', 'MeridianLabel', 'on', 'ParallelLabel', 'on')
setm(gca,'mlabelparallel',-20)
load coastlines
Contours = [0.001 0.01 0.1 1 10 100];
[c,h] = contourfm(latlim, lonlim, u, log(Contours));
colorbar('YTick', log(Contours), 'YTickLabel', Contours);
myColorMap = jet(256).^.3;
myColorMap(1,:) = [1];
colormap(myColorMap)
colorbar
caxis(log([Contours(1) Contours(length(Contours))]));
colorbar('FontSize', 12, 'YTick', log(Contours), 'YTickLabel', Contours);
geoshow(coastlat, coastlon,'Color', 'k')
Contour level, V, in contourfm(lat,lon,Z, V) does not scale your data or colour. It works in a different way than what you thought.
Let's see one example first:
u = rand(8)+0.1; u(1:2,:) = 0; u(5:6,:) = 10; u(7:8,:) = 100;
V = [0,1,40,100];
contourfm([0,1], [0,1], u, V);
mycm = jet(256).^.3; mycm(1,:) = 1;
colormap(mycm)
contourcbar('FontSize', 12, 'YTick', V, 'YTickLabel', V);
where u is
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0.1947 0.6616 0.2413 0.6511 0.4403 0.9112 1.0016 0.5654
0.8422 0.3159 0.5695 0.6478 0.9933 0.1686 0.8387 0.5362
10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10
100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100
As you can see, for V = [0,1,40,100] all values from 0 to 1 are white, values from 1 to 40 are cyan and above are red.
Therefore, you must scale your u then assign appropriate contour level. Use contourcbar instead of colorbar to check the colours first.
Apart from the problem with contour level, I suspect the u parameter contains negative values. The colour at the bottom of the colour bar is always assigned to the minimum z value. You must ensure 0 is the minimum value in u, i.e. remove the negative values.
I am coding to make a trendline on my scatter plot.
data=[];
for k=1:100
int=0;
for t=1:100
if k_star_90(k,t)~=0
int=int+k_star_90(k,t);
end
if k_star_90(k,t)==0 && int~=0
data=[data int];
int=0;
end
end
end
intervals = linspace(0, 1, 100);
h1 = histc(data, intervals);
scatter(intervals, h1, 'r');
set(gca,'xscale','log')
set(gca,'yscale','log')
picture of plot result
This is in log-log scale. On this plot, I want to draw y=ax+b(1st order) trendline. I am not sure how to do it.
I will really appreciate your help
I'm not sure I understood your intention correctly, but if you need a trend line you may do something like this
intervals = [0.01 0.02 0.2 0.1 0.3 0.5 0.03 0.4 0.15 0.2 0.2 0.25 1 0.9 0.8 0.8 0.7];
h1 = [70 40 4 20 2 3 60 10 50 40 10 20 1 2 3 1 2] ;
coeffs = polyfit(intervals, h1, 1);
xFitting = 0:0.01:1;
yFitted = polyval(coeffs, xFitting);
scatter(intervals, h1, 'r');
set(gca,'xscale','log');
set(gca,'yscale','log');
grid on;
hold on;
plot(xFitting, yFitted, 'b', 'LineWidth', 2);
hold off;
ylim([1 80]);
xlabel('intervals');
ylabel('h1');
Here is your trend in Log scale:
Og course it does not look like a first order trend. To depict it as a line you need to go back to a normal plot:
My code:
Screen('OpenWindow', 0, [0 0 0], [0 0 600 600])
Screen('FillRect', win, [0 255 0 ], [0 0 50 50]);
Screen('Flip', win);
I understand that the documented line is:
Screen('FillRect', windowPtr [,color] [,rect] )
With windowPtr as just a placeholder which needs to be replaced with a variable name to identify this particular shape. However when I'm using win to identify it, I am constantly getting the error:
Undefined function or variable 'win'.
Error in Practice_Script_1 (line 17)
Screen('FillRect', win, [0 255 0 ], [0 0 50 50]);
I don't understand what I'm doing wrong and it's probably just some noob mistake that is really frustrating me.
I don't have the Psychtoolbox, but this error message typically means that the (in this case) win variable is not defined. Have you initialized this variable prior to calling the above lines of code?
The following link creating experiments using MATLAB and Psychtoolbox has some sample code and they define the win variable as
win = Screen('OpenWindow',0, [900 900 1000], [10,10, 1100,1100]);
You will need to do something similar. Another link MATLAB cookbook does the following
% Initialize the screen with a black background
% rect is the coordinates of the screen
[win rect] = Screen('OpenWindow', 0, [0 0 0]);
ovalColor = [0 255 0]; % RGB color for the oval
rectColor = [255 0 0]; % RGB color for the rectangle
ovalRect = [100 100 300 200]; % Coordinates [x1 y1 x2 y2]
rectRect = [100 250 300 350]; % Coordinates [x1 y1 x2 y2]
Screen('FillOval', win, ovalColor, ovalRect);
Screen('FillRect', win, rectColor, rectRect);
Screen('Flip', win);
Try either option and see what happens.
I have three different plots inside a loop: two plots have border, but one doesn't:
I want all of them to have a black border. I tried to make it by using box but the problem persists.
hold on
figure(1),plot((delta1),Sref1,'*','Color',colors(i,:));title('Frequency [500MHz-1GHz]')
gcf=figure(1);
set(gcf,'Position', [0 0 290 245]);
hold off
hold on
figure(2),plot((delta2),Sref2,'*','Color',colors(i,:));title('Frequency [1GHz-1.5GHz]')
gcf=figure(2);
set(gcf,'Position', [0 0 290 245]);
hold off
hold on
figure(3),plot((delta3),Sref3,'*','Color',colors(i,:));title('Frequency [1.5GHz-2GHz]')
gcf=figure(3);
set(gcf,'Position', [0 0 290 245]);
hold off
Just add box on before the first hold off line.
This code worked for me (Matlab 2012b):
hold on
figure(1),plot(1:10);title('Frequency [500MHz-1GHz]')
gcf=figure(1);
set(gcf,'Position', [0 0 290 245]);
box on
hold off
hold on
figure(2),plot(1:10);title('Frequency [1GHz-1.5GHz]')
gcf=figure(2);
set(gcf,'Position', [0 0 290 245]);
hold off
hold on
figure(3),plot(1:10);title('Frequency [1.5GHz-2GHz]')
gcf=figure(3);
set(gcf,'Position', [0 0 290 245]);
hold off