![]() I generally try to avoid this because it's not explicit which dimension you want to look along for matrices.Īside from just repeating info though, I want to show you could do this much more efficiently with logical indexing, and remove the problematic loop entirely. ![]() Others recommend length(x) which is max(size(x)). I would use size(x,2) (number of columns in x) or numel(x) (number of elements in x). If there are any suggestions you have for improving my questions in the future that would be good too!Īs stated in comments and RadioJava's answer, you need to check your loop. If you could provide any suggestions that could help me with this function that would be greatly appreciated, thank you! The question also asks me to use if statements, so I can't try using other methods to produce the piecewise method function, and from my searching around, there didn't seem to be many examples of if statements in piecewise functions. I tried reconstructing the for loop a number of times from the basic level up, but when I started putting in the equations it began to fall apart again, so I believe something could be wrong with my equations (which is why I put brackets everywhere, just in case). Now this suggests to me that the array is being properly created, but for one reason or another the for loop isn't running properly, or as expected. It produces this result for the variable solution. % equations to enact upon the given value of x % piecewise_method will choose from one of the three specified % given the value of the input x, the function I have only recently began working with MATLAB for Uni this year, and as a homework quiz question I was asked to create a piecewise function (that I have called "piecewise_method") that is able to enact a different equation on "x" depending on if "x" is below 0, between 0 and 8, or above 8.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |