Reaching the array read from .txt file
6 views (last 30 days)
Show older comments
I have a bunch of recorded data as an array on .txt file.
I'm reading the files and creating an array on matlab by following lines;
data = ['data' num2str(i) '.txt'];
load(data)
Now I just need to crop the array size. To do that I simply use the following code;
data0 = data0(100:1)
But I need to do that on multiple numbers of data in a for loop. The question is that after loading the "data" by load command, how can I reach this array, which will be named as "data0" after the first iteration.
2 Comments
Azzi Abdelmalek
on 21 Jul 2013
Edited: Azzi Abdelmalek
on 21 Jul 2013
Zoom commented
I mean after loading the data by load(data) command, I have an array called data0 (this is in a for loop, so "data0" is created after the first iteration of the loop, then "data1" will be created so and so forth.) Now I need to crop this array collaed data0 since I'll be cropping all the arrays named data0, data1, data2... I need to do that in the same for loop as well. However I can't write
data0 = data0(1001:1)
because the in the next iteration data1 will be the array that I want to crop, So, instead I have to find a way like;
data = ['data' num2str(i) '.txt'];
load(data)
dummy = load(data) 'data' num2str(i) = dummy(1001:1)
here through load(data) command I create the data0 array and then assigning the same content to a dummy array and then assigning the cropped dummy to original data0. For sure there is nothing like the following line;
'data' num2str(i) = dummy(1001:1)
But what I'm looking is something doing that.
Answers (1)
Azzi Abdelmalek
on 21 Jul 2013
for k=1:n
filename=sprintf('data%d',k);
data=load(filename);
data0=data.(filename)
%do
end
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!