Reaching the array read from .txt file

2 Ansichten (letzte 30 Tage)
zoom
zoom am 21 Jul. 2013
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 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 21 Jul. 2013
I think this is not clear
Azzi Abdelmalek
Azzi Abdelmalek am 21 Jul. 2013
Bearbeitet: Azzi Abdelmalek am 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 21 Jul. 2013
for k=1:n
filename=sprintf('data%d',k);
data=load(filename);
data0=data.(filename)
%do
end
  1 Kommentar
zoom
zoom am 21 Jul. 2013
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

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by