필터 지우기
필터 지우기

How to convert sequence of numbers into text and display on screen

조회 수: 2 (최근 30일)
Cai Chin
Cai Chin 2020년 8월 22일
댓글: Cai Chin 2020년 8월 22일
I am using MATLAB R2020a Psychtoolbox on Mac OS. I am trying to display sequences of numbers generated from a random Gaussian distribution and have tried 'num2str' and 'char' functions but these haven't worked. These are the sequences. The 'dis' function generates the numbers.
% Define sequences
seq1 = dis(20, 10, 100, 0, 5);
seq2 = dis(10, 10, 100, 0, 5);
seq3 = dis(10, 10, 100, 0, 5);
% dis function
function x = dis(va, mu, ul, ll, nvals)
n = makedist('normal','mu',mu,'sigma',sqrt(va));
t = truncate(n,ll,ul);
x = round(random(t,nvals,1));
end
  댓글 수: 7
Adam Danz
Adam Danz 2020년 8월 22일
편집: Adam Danz 2020년 8월 22일
To add space between the numbers,
sprintf('%.4f ', rand(1,5))
Another approach, although much less efficient,
str = num2str(rand(1,5));
strSpace = regexprep(str, ' +', ' ')
Cai Chin
Cai Chin 2020년 8월 22일
Thanks, that worked perfectly. In Psychtoolbox, when you enter the script name into the command window, the screen becomes blank and the background changes to a specified colour. I was then displaying sequences of numbers in a virtual triangle, each number separated by a space.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by