MATLAB for Engineers - Introduction to for Loops (Part 3 of 4): Indexing and Storage in Arrays

  Рет қаралды 37,590

Spartan Professor

Spartan Professor

Күн бұрын

A for loop is a loop structure for repeating a calculation a pre-defined number of times. In this video, we'll use a for loop to store data inside of an array. First, I'll introduce you to how MATLAB handles arrays and array indexing. Then, I'll take you through a flow chart of an example problem to visualize how an array can be updated during each loop pass. Finally, I'll walk you through the implementation of a for loop in MATLAB with array indexing and storage in an array. If you are unfamiliar with for loops, I'd recommend watching Parts 1 and 2 of the series (links below).
This is Part 3 of a 4 Part Series on for Loops.
Part 1 introduces the basic structure of a for loop and demonstrates a loop pass. Link to Part 1: • MATLAB for Engineers -...
Part 2 focuses on updating the value of a variable during each loop pass. Link to Part 2: • MATLAB for Engineers -...
Part 4 will introduce combining loops and logic by nesting the conditional statements if, elseif, and else inside of a loop. Link to Part 4: • MATLAB for Engineers -...
The background music in the intro and outro was written and produced by Michael J Calamas for the exclusive use of David Calamas.

Пікірлер: 28
@angie25601
@angie25601 3 жыл бұрын
Thank you for your video, I am using them to complement my practice with Matlab. Sometimes my book is difficult to follow but with your videos I can understand better the concepts and solve the exercises of my book.
@kapisotieno2302
@kapisotieno2302 3 жыл бұрын
Good lecture. I understand clearly the objective of this tutorial. I yearn for more. thanks
@ranapratap4961
@ranapratap4961 3 жыл бұрын
glad u r back. I love ur videos bro.
@user-tx5vx5if1r
@user-tx5vx5if1r 3 жыл бұрын
Really nice and helpful videos! Greetings from Greece!
@SpartanProfessor
@SpartanProfessor 2 жыл бұрын
Thanks for watching!
@khadijahblagmon3077
@khadijahblagmon3077 3 жыл бұрын
You are a life saver!
@unstoppable5174
@unstoppable5174 2 жыл бұрын
U are my hero I swear !! Thankfully
@krisatd4815
@krisatd4815 Жыл бұрын
very good lecture, please add more and more videos
@ravindrakhakural6757
@ravindrakhakural6757 Жыл бұрын
Great Explanation, you are able to save my dream to be graduated
@AdityaSingh-kw8bi
@AdityaSingh-kw8bi 3 жыл бұрын
great to see you again bro we will be rich soon :) loves your videos
@ayush3334
@ayush3334 3 жыл бұрын
dude, thanks so much!!!!!!!!!!!!!!!!!
@Antonio-ms3gb
@Antonio-ms3gb 3 жыл бұрын
Catapimbas ! Muito bom !
@ivanatoche6142
@ivanatoche6142 Жыл бұрын
Thank you a lot
@SpartanProfessor
@SpartanProfessor Жыл бұрын
You are welcome!
@sam-kx3ty
@sam-kx3ty 2 жыл бұрын
talented man haha!!
@aklilug6597
@aklilug6597 3 жыл бұрын
can u suggest on handling more than two indexes or variables in matlab. let's, for example, assume that Y is function of three variable, x,z,t and we want to have values of y as all variables change and store results at point of my interest. for example store values of y as t varies and x and z are kept at specific values.
@hz2909
@hz2909 Жыл бұрын
How can we detect a sign change in a vector using for loop
@sadiq114
@sadiq114 3 жыл бұрын
Very good way of teaching. Are you going to teach from the Matlab Book "Matlab for Engineers"? And if yes, then which edition? Further, are you going to continue these lectrures it or not? Regards
@sadiq114
@sadiq114 3 жыл бұрын
@@SpartanProfessor thanks for your prompt reply. Can you email me that book? matlabbeginner@gmail.com
@eedeatlikkle3652
@eedeatlikkle3652 2 жыл бұрын
Quick q, if you want to just use one value of y, say when i = 3 for some other calculation, how do you do that. Because if I write y in the conmand window it just gives me the latest y value (when i is 5)?? Would really appreciate a quick reply thanks
@SpartanProfessor
@SpartanProfessor 2 жыл бұрын
You can use an array index to reference the element you are interested in. In your case, y(3) would return the third element in y.
@user-uy3hd2mv9t
@user-uy3hd2mv9t Жыл бұрын
what if I wrote the following instead? for x=0:2:8; y=x^2 end is it the same? Thanks
@ogechiogbonna368
@ogechiogbonna368 4 ай бұрын
It's not the same the final output of your code will be a scalar i.e a 1 by 1 matrix But the final output of the code he has written will output an array of 1 x 5 matrix
@stephenoni2019
@stephenoni2019 2 жыл бұрын
why'd you do it this way and not like the way you did in previous videos? why did you introduce "i" abruptly?
@SpartanProfessor
@SpartanProfessor 2 жыл бұрын
That's a good question. The index variable, i, is used to store values in a specific element in an array. For example, A(1) is the first element in A (where i = 1). Similarly, A(5) is the fifth element in A (where i = 5). So an array index can be used to tell MATLAB where to store a value. It can also be used to extract a value from an array from a specific location. I'm realizing this is difficult to explain in a comment... I may create a separate video for this topic. Thanks for commenting.
@jacobhouston1655
@jacobhouston1655 3 жыл бұрын
This y(i), the i character is giving me SUCH A HARD TIME watching your vidoes. Everything is smooth until that (i) comes up. Could yo uplease explain this whole (i) concept in a video by itlsef? Very frustrating. :(
@jacobhouston1655
@jacobhouston1655 3 жыл бұрын
I despise this (i). I don't understand it.
@stephenoni2019
@stephenoni2019 2 жыл бұрын
I had trouble with this as well for many years now, and I think I just realized that i is a counter for all the numbers in the array, that is, it holds all the numbers you want to calculate a function for. So for y(i), you are calculating the function y at whatever value i is. That is the way I understand it at the moment. "i" can also be any letter or letters or whatever you want it to be, as long as you stay consistent during the course of your code.
KINDNESS ALWAYS COME BACK
00:59
dednahype
Рет қаралды 151 МЛН
Cat Corn?! 🙀 #cat #cute #catlover
00:54
Stocat
Рет қаралды 15 МЛН
DEFINITELY NOT HAPPENING ON MY WATCH! 😒
00:12
Laro Benz
Рет қаралды 50 МЛН
AES: How to Design Secure Encryption
15:37
Spanning Tree
Рет қаралды 152 М.
Signal Processing with MATLAB
21:11
Opti-Num Solutions
Рет қаралды 105 М.
MATLAB for Engineers - Conditional Statements if, else, and elseif
12:52
Spartan Professor
Рет қаралды 76 М.
Working with Arrays in MATLAB
8:21
MATLAB
Рет қаралды 215 М.
threading vs multiprocessing in python
22:31
Dave's Space
Рет қаралды 566 М.
Pointers and dynamic memory - stack vs heap
17:26
mycodeschool
Рет қаралды 1,4 МЛН
"While Loops" and "For Loops" in MATLAB
9:24
James Smith
Рет қаралды 20 М.
KINDNESS ALWAYS COME BACK
00:59
dednahype
Рет қаралды 151 МЛН