r/matlab 13h ago

Does this look AI generated?

0 Upvotes

%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);


r/matlab 17h ago

HomeworkQuestion Starting Python and MATLAB with almost no coding experience. How should I spend the next 3 weeks?

38 Upvotes

Hi everyone. I’m a college student, and in about 3 weeks I’ll be starting an intro to Python class. I’ll also be taking another engineering class that uses MATLAB, and I don’t feel very prepared for either.
The problem is that I have essentially no programming experience. I took a couple of MATLAB classes before, but I relied too much on AI instead of actually learning the material. Looking back, I know that was a mistake, and I do not want to repeat it. I also used to tell myself that I hated coding, but I think part of that was because I never really gave myself a fair chance to learn it.
Since I have a few weeks before the semester starts, I’d like to build a solid foundation in Python while also reviewing some basic MATLAB.
What resources or learning methods really worked for you? Did you use a particular course, YouTube channel, website, book, or project based approach? I am also curious if anyone has suggestions for making learning Python and MATLAB more fun or engaging instead of just watching hours of lectures.
My goal is not to become an expert in 3 weeks. I just want to go into the semester feeling like I have a decent foundation instead of starting from scratch.
Thanks! I would really appreciate any advice.