The purpose of code on programming

조회 수: 7 (최근 30일)
Shuoze Xu
Shuoze Xu 2022년 3월 27일
댓글: Shuoze Xu 2022년 3월 27일
Hi.
I met a few questions when i watch this code
i seen the comment, but i have no idea why the picture produced like that.
i also confuse for the imageData=[imageData; imageRow]; i know the function of ";", but why it used in here?
% make a 2d array of values.
imageData=[]; % set up an empty array
imSize=100;
numRows=imSize;
numCols=imSize;
%populate using a nested loop
for row=[1:numRows]
imageRow=[]; %empty vector for row
for col=[1:numCols]
pixelVal=uint8((row+col)/(imSize*2) * 255); % make a pixel val in 0..255
imageRow=[imageRow pixelVal]; %add value for pixel
end
imageData=[imageData; imageRow]; % add row of pixels
end
% display as an image
imshow(imageData);
% save as an image
imwrite(imageData,'test.png');
% load an image
newImageData=imread('test.png');
% print information about what is stored in the variable
whos newImageData;

채택된 답변

Image Analyst
Image Analyst 2022년 3월 27일
I'm not sure why you said "i know the function of ";", but why it used in here?"
In
imageData=[imageData; imageRow];
the first semicolon says that the rowVector imageRow is to be concatenated below the 3-D matrix imageData.
They're essentially building up the matrix row-by-row by appending the current row to the matrix they're building up.
The second semicolon tells it not to type the whole matrix -- all values of it -- to the command window.
  댓글 수: 3
Image Analyst
Image Analyst 2022년 3월 27일
That's the formula they're using to make the values go from 0 in the upper left to 255 in the lower right.
Shuoze Xu
Shuoze Xu 2022년 3월 27일
I got it.
Thank you for your help.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by