I’m trying to tidy up my code. I have an array with 5 columns, each of which is assigned to a variable. At present, I use:
x = inputData(i,1);
y = inputData(i,2);
currentSampleTime = inputData(i,3);
velocityX = inputData(i,4);
velocityY = inputData(i,5);
I thought I could tidy things up a bit by just doing the following:
[x y currentSampleTime velocityX velocityY] = inputData(i,:);
Apparently this does not work. I presume there must be an elegant solution?
If inputData was a cell array then you could do this:
However, since you are indexing the row with the variable
ican I assume that this is inside aforloop?If so I would just do the following before the loop?
Then just use
x(i)y(i)etc inside of your loop.… or depending on how
inputDatais generated try to create the necessary arrays when reading in or creating inputData.Also, on a personal note I don’t like using
ias a variable in m-code because it can easily get confused with the imaginary number if not properly initialized.