Efficient ways of setting up a matrix
Hey guys, thanks in advance, I'm quite new to matlab!
So I'm looking to create a nxm matrix which for every element is a function of two variables p and t. The catch is, I need p to remain constant in the rows, and t to progress, and t to be constant in the columns, and p to vary. I would like the vectors p and t to have easy to input start stop and increment values.
I've considered decomposing the function into elementry steps, and then applying matrix algebra to apply successive transforms on the elements of my matrix, until the over all transform is the function value at each element of the matrix, I've also just found out about cat() and I'm thinking about constructing a row vector matching what I need, and then running a loop, creating more vectors, with slightly different p values, and then cat them together?
Thanks guys! I cant help but feel like I'm missing something easy here
Posted Feb 3, 2019, 10:39 PM UTC
Not sure if I'm correctly interpreting what you're looking for, but it sounds like you're describing something that you could construct from the outputs of the
meshgridfunction.I was thinking the same thing, but I wasnt sure if I could then define a function f(t,p) and then use each t and p value at each element of the array, and replace it in the matrix with the function value, considering t and p, as its inputs.
My end result would be an array of f values which took in t and p values based on its position in the matrix, based on how I define t and p in the first place?
Again, I'm not 100% sure that we're on the same page, but if I understand you correctly then this is basically exactly the purpose of
meshgrid.I'll post an example code snippet once I'm back on my computer (on mobile currently and heading to bed shortly, so not until tomorrow)
Okay, I am familiar with meshgrid, but I would like help with plugging in the values of t and p at that element, into the function f
Sorry I haven't gotten to this earlier. What does your function f(t,p) look like?