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일
I think this is not clear
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