I have loaded a set of 50 files into matlab workspace. (from data1 to data50).
The size of each one is 721*176. I want to extract only the first 144 lines of each data and store it in another one.
For example:
newData1 = data1(1:144,:);
My question is: How can I do this using a loop to process all data at once?
That depends on how you store the data.
The best way in your case would be 3D array:
First, allocate the array (As @HighPerformanceMark points out correctly):
Then, populate it with values:
In that case, just use the following selection:
Another plausible way to store the data is cell array. It is useful since 3D array cannot handle different size matrixes.
In this case, use
cellfun:If you still insist on storing the data in separate variables rather than in an array, you can use
eval. That is the least recommended way.