I have a for loop that loops over one array…
for i=1:length(myArray)
In this loop, I want to do check on the value of myArray and add it to another array myArray2 if it meets certain conditions. I looked through the MATLAB docs, but couldn’t find anything on creating arrays without declaring all their values on initialization or reading data into them in one shot.
Many thanks!
I’m guessing you want something more complicated than
The easiest (but slowest) way to do what you’re asking is something like
You can sort of optimize this with something like
You might also want to look into ARRAYFUN.