Ich schreibe ein Skript, in dem ich die Breite der Lücke zwischen zwei Positionen variiere, wo ich kontinuierlich Gesichter blitze und eine Bewertung vom Teilnehmer bekommen, wie verzerrt die Gesichter sehen von 0-9 aus. Ich habe 5 Ebenen und 5 Bewertungen, und ich bekomme Antworten mit GetChar. Ich habe am Ende eine Reihe von Zahlen (zum Beispiel '76421'), aber ich möchte das in eine Tabelle umwandeln, auf der ich eine Regression ausführen kann, mit meinen x-Werten der Abstand zwischen den zwei Positionen in Pixeln und den y-Werten als die Bewertungen der Verzerrung. Ich verwende psychtoolbox auf MATLAB unter Windows. Jeder Rat, wie dies zu tun wäre, würde sehr geschätzt werden.MATLAB: Wie man eine Zeichenfolge in eine Tabelle konvertiert
hier ist mein Skript:
% Clear the workspace and the screen
sca;
close all;
clearvars;
Screen('Preference', 'SkipSyncTests', 1);
%reading in all images
baseDir=pwd;
cd([baseDir,'\Images']) %change directory to images folder
jpegFiles = dir('*.jpg'); % create a cell array of all jpeg images
%loop to read in all images
for k=1:size(jpegFiles,1)
images{k}=imread(jpegFiles(k).name);
end
cd(baseDir) %change directory back to the base directory
% Here we call some default settings for setting up Psychtoolbox
PsychDefaultSetup(2);
% Get the screen numbers
screens = Screen('Screens');
% Draw to the external screen if avaliable
screenNumber = max(screens);
% Define black and white
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);
% Open an on screen window
[w, windowRect] = PsychImaging('OpenWindow', screenNumber, white);
% Get the size of the on screen window
[screenXpixels, screenYpixels] = Screen('WindowSize', w);
% Query the frame duration
ifi = Screen('GetFlipInterval', w);
% Set up alpha-blending for smooth (anti-aliased) lines
Screen('BlendFunction', w, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
% Setup the text type for the window
Screen('TextFont', w, 'Ariel');
Screen('TextSize', w, 36);
% Get the centre coordinate of the window
[xCenter, yCenter] = RectCenter(windowRect);
% Here we set the size of the arms of our fixation cross
fixCrossDimPix = 40;
% Now we set the coordinates (these are all relative to zero we will let
% the drawing routine center the cross in the center of our monitor for us)
xCoords = [-fixCrossDimPix fixCrossDimPix 0 0];
yCoords = [0 0 -fixCrossDimPix fixCrossDimPix];
allCoords = [xCoords; yCoords];
% Set the line width for our fixation cross
lineWidthPix = 4;
% Draw the fixation cross in white, set it to the center of our screen and
% set good quality antialiasing
Screen('DrawLines', w, allCoords,...
lineWidthPix, black, [xCenter yCenter], 2);
%defining the left and right positions
%defining the centre or the x and y axis
screen_size = get(0, 'ScreenSize');
xCent = screen_size(3)/2;
yCent = screen_size(4)/2;
rightposition1 = [xCent+(xCent/4)+50, yCent-240, xCent+(xCent/4)+640+50, yCent+240]; %right [top(?) left coordinates(X,Y),Bottom(?) right (X,Y)
leftposition1 = [xCent-((xCent/4)+640+50), yCent-240, xCent-((xCent/4)+50), yCent+240]; %left
rightposition2 = [xCent+(xCent/4), yCent-240, xCent+(xCent/4)+640, yCent+240]; %right [top(?) left coordinates(X,Y),Bottom(?) right (X,Y)
leftposition2 = [xCent-((xCent/4)+640), yCent-240, xCent-((xCent/4)), yCent+240]; %left
rightposition3 = [xCent+(xCent/4)-50, yCent-240, xCent+(xCent/4)+640-50, yCent+240]; %right [top(?) left coordinates(X,Y),Bottom(?) right (X,Y)
leftposition3 = [xCent-((xCent/4)+640-50), yCent-240, xCent-((xCent/4)-50), yCent+240]; %left
rightposition4 = [xCent+(xCent/4)-100, yCent-240, xCent+(xCent/4)+640-100, yCent+240]; %right [top(?) left coordinates(X,Y),Bottom(?) right (X,Y)
leftposition4 = [xCent-((xCent/4)+640-100), yCent-240, xCent-((xCent/4)-100), yCent+240]; %left
rightposition5 = [xCent+(xCent/4)-150, yCent-240, xCent+(xCent/4)+640-150, yCent+240]; %right [top(?) left coordinates(X,Y),Bottom(?) right (X,Y)
leftposition5 = [xCent-((xCent/4)+640-150), yCent-240, xCent-((xCent/4)-150), yCent+240]; %left
%making textures
for k=1:580
texture1(k)=Screen('MakeTexture',w,images{k});
end
for a=1:1
%showing pictures
for k=randperm(50) %Shows a random string of 50 images
Screen('DrawTexture',w,(texture1(k)), [], leftposition1);
Screen('DrawTexture',w,(texture1(k+25)), [], rightposition1); %random string starting from a different image
Screen('DrawLines', w, allCoords,...
lineWidthPix, black, [xCenter yCenter], 2);
Screen(w,'Flip');
pause(0.2);
end
%rating text
DrawFormattedText(w,'Rate distortion 0-9','center','center',[255 255 255]);
Screen(w,'Flip');
FlushEvents;
[ch, when]=GetChar;
responsea(a)=ch
Screen(w,'Flip');
end
for b=1:1
%showing pictures
for k=randperm(50) %Shows a random string of 50 images
Screen('DrawTexture',w,(texture1(k)), [], leftposition1);
Screen('DrawTexture',w,(texture1(k+25)), [], rightposition1); %random string starting from a different image
Screen('DrawLines', w, allCoords,...
lineWidthPix, black, [xCenter yCenter], 2);
Screen(w,'Flip');
pause(0.2);
end
%rating text
DrawFormattedText(w,'Rate distortion 0-9','center','center',[255 255 255]);
Screen(w,'Flip');
FlushEvents;
[ch, when]=GetChar;
responseb(b)=ch
Screen(w,'Flip');
end
for c=1:1
%showing pictures
for k=randperm(50) %Shows a random string of 50 images
Screen('DrawTexture',w,(texture1(k)), [], leftposition3);
Screen('DrawTexture',w,(texture1(k+25)), [], rightposition3); %random string starting from a different image
Screen('DrawLines', w, allCoords,...
lineWidthPix, black, [xCenter yCenter], 2);
Screen(w,'Flip');
pause(0.2);
end
%rating text
DrawFormattedText(w,'Rate distortion 0-9','center','center',[255 255 255]);
Screen(w,'Flip');
FlushEvents;
[ch, when]=GetChar;
responsec(c)=ch
Screen(w,'Flip');
end
for d=1:1
%showing pictures
for k=randperm(50) %Shows a random string of 50 images
Screen('DrawTexture',w,(texture1(k)), [], leftposition4);
Screen('DrawTexture',w,(texture1(k+25)), [], rightposition4); %random string starting from a different image
Screen('DrawLines', w, allCoords,...
lineWidthPix, black, [xCenter yCenter], 2);
Screen(w,'Flip');
pause(0.2);
end
%rating text
DrawFormattedText(w,'Rate distortion 0-9','center','center',[255 255 255]);
Screen(w,'Flip');
FlushEvents;
[ch, when]=GetChar;
responsed(d)=ch
Screen(w,'Flip');
end
for e=1:1
%showing pictures
for k=randperm(50) %Shows a random string of 50 images
Screen('DrawTexture',w,(texture1(k)), [], leftposition5);
Screen('DrawTexture',w,(texture1(k+25)), [], rightposition5); %random string starting from a different image
Screen('DrawLines', w, allCoords,...
lineWidthPix, black, [xCenter yCenter], 2);
Screen(w,'Flip');
pause(0.2);
end
%rating text
DrawFormattedText(w,'Rate distortion 0-9','center','center',[255 255 255]);
Screen(w,'Flip');
FlushEvents;
[ch, when]=GetChar;
responsee(e)=ch
Screen(w,'Flip');
end
%press space to finish%
DrawFormattedText(w,'thank you fo completing the eperiment. press any key to finish','center','center',[255 255 255]);
Screen(w,'Flip');
% Wait for a key press
KbStrokeWait;
% Clear the screen
sca;
responses = [responsea,responseb,responsec,responsed,responsee] %gives a string
%you need to record responses in a table and save the table using
%the subject code
%you need to plot x as the pixels between and y as the level of distortion
%then run a regression
Bitte posten Sie eine [mcve], die den Fehler im Gegensatz zu dumping alle Ihren Code für uns durch Crawlen reproduziert. – Adriaan