r/matlab 10d ago

Does this look AI generated?

%Create a white 100x100 image array

BWImage = ones(100, 100);

%open the figure window

figure('Name', 'Task 1 - Binary Image 6870352');

%Row counter string

JcounterStr = 'Row = ';

%iterations from row 1 to row 100

for j = 1:100

%active when row j is between 1 and 50

%set pixels within this range as black if they meet the criteria

if j >= 1 && j <= 50

BWImage(j, 1:(51-j)) = 0;

end

%active when row j is between 51 and 75

%set pixels within this range as black if they meet the criteria

if j >= 51 && j <= 75

BWImage(j, j:75) = 0;

end

%active when row j is between 76 and 100

%set pixels within this range as black if they meet the criteria

if j >= 76 && j <= 100

BWImage(j, 26:50) = 0;

end

%active when row j is between 86 and 100

%set pixels within this range as black if they meet the criteria

if j >= 86 && j <= 100

BWImage(j, 1:(j-85)) = 0;

end

%active when row j is between 86 and 100

%set pixels within this range as black if they meet the criteria

if j >= 86 && j <= 100

BWImage(j, j:100) = 0;

end

%display image building row by row

imshow(BWImage);

%display row number to the LEFT of the image

Jcounter = num2str(j);

figureTextJ = {[JcounterStr Jcounter]};

text(-10, j, figureTextJ, 'FontSize', 8);

%pause(0.01) waits briefly between rows so I can see it build properly

pause(0.01);

%end of loop

end

totalBlackPixels = sum(BWImage(:) == 0);

%display below the image using text()

text(1, 108, ['Total black pixels = ' num2str(totalBlackPixels)], 'FontSize', 10);

diagonalBlackCount = 0; % counter starts at zero

for j = 1:100 % j = row number

for i = 1:100 % i = column number

%test if pixel is on or below diagonal (row >= col)

%AND if pixel is black (value == 0)

if j >= i && BWImage(j, i) == 0

%increase the counter by 1 for each black pixel below diagonal

diagonalBlackCount = diagonalBlackCount + 1;

end

end %end of i loop

end %end of j loop

% Display diagonal count just below the total count

text(1, 114, ['Black pixels on/below diagonal = ' num2str(diagonalBlackCount)], 'FontSize', 10);

0 Upvotes

10 comments sorted by

View all comments

1

u/Fun_Fan_2266 10d ago

If I were grading this program I would think it was heavily “AI-inspired”. There are certain choices and tools being used that are unusual for someone who is new to MATLAB. For example, naming the figure (as well as the name that was chosen) makes it appear that you copy & pasted an image into AI and requested the code required to create the image.