Reaching the array read from .txt file

2 次查看(过去 30 天)
zoom
zoom 2013-7-21
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 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2013-7-21
编辑:Azzi Abdelmalek 2013-7-21
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.

请先登录,再进行评论。

回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2013-7-21
for k=1:n
filename=sprintf('data%d',k);
data=load(filename);
data0=data.(filename)
%do
end
  1 个评论
zoom
zoom 2013-7-21
That works to some extent.
filename=sprintf('data%d',k);
Allows me to get the name of the array that I'm interested in. But I can not load the array by using "filename", error message says there is no such file, even though I have an array named data1

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by