필터 지우기
필터 지우기

AppDesigner Code Simplification Help

조회 수: 1 (최근 30일)
Carlos Garciamendez
Carlos Garciamendez 2021년 3월 25일
댓글: mlb chen 2022년 9월 21일
Hello all, currently developed a program that runs well in AppDesigner. However, I am finding that a lot of my code is copy pasted several times (around 5-6).
Therefore, my question is to see if there is a way to create a varible/function that stores all of these lines are code that are repeated several times?
For reference here is an example of a segment of code that is repeated:
% Define the SLM struct
SLM.window = Screen('Preference', 'VisualDebuglevel', 3);
SLM.window = Screen('Preference','SkipSyncTests',2); % Skips the showing of Pink Screen
black = BlackIndex(2); % Assign a black index to 2nd screen
SLM.window = Screen('OpenWindow',2,black); % Opens the 2nd screen and shows black
% Create blank image
black_background = zeros(1920,1080); % Assigns Zeros to all background matrix to show black
blank_image_ptr = Screen('OpenOffscreenWindow',SLM.window,2); % Opens an off screen i.e. background screen on 2nd window
% textureIndex = Screen('MakeTexture', blank_image_ptr, black_background);
% Screen('DrawTexture', blank_image_ptr, textureIndex);
Screen('PutImage',blank_image_ptr,black_background); % Assign black background to blank image ptr in Off screen
% Screen(SLM.window,'DrawTexture',black_background); % start by projection of a blank image
Screen(SLM.window,'PutImage',black_background); % start by projection of a black background on off screen
Screen(SLM.window,'Flip'); % Project image on on_screen
% First create image pointers
window_ptrs = zeros(1,image_total); % vector for storing the pointers to each image
Also in the last line, "images_total" is an input that is taken from a text field in the GUI.
Thanks
  댓글 수: 1
mlb chen
mlb chen 2022년 9월 21일
I would like to ask, how to solve the problem that the number of input parameters is insufficient?The procedure is basically similar to yours.

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

답변 (1개)

Vimal Rathod
Vimal Rathod 2021년 5월 19일
Hello,
With the information given, I am assuming that you want to know how to package the above snippet of code in a function and reuse it. There are two ways I could think of as a solution to your question here. First is to create a function put the above snippet of code and as a parameter to the function give "images_total" or any variable and pass it to the function when calling it. The second way is only when you want to run your code snippet in certain events for that you could use callbacks in app designer.

카테고리

Help CenterFile Exchange에서 Image display and manipulation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by