How would i run different events from the same .txt file?

1 回表示 (過去 30 日間)
Feliciano Döring
Feliciano Döring 2018 年 4 月 19 日
編集済み: Feliciano Döring 2018 年 4 月 20 日

I run a program that uses the following information of a .txt file

4 0 0
1 1 1
3 1 1
2 3 1
3 2 1

in which the first number is the number of stations and than the coordinates x,y,z for these four stations. Now i want to expand the program to run for more events in which i have like

4 0 0
1 1 1
3 1 1
2 3 1
3 2 1
3 0 0
1 3 1
2 3 3
3 1 2
.
.
.
n 0 0 
xn yn zn

till 'n' events, being this all separate events. Is there a way to read it as different blocks but with one program? P.S. the zeros after the number of stations is because i use the command 'load' ideally i wouldn't write these zeros. P.S.2 the number of stations and the coordinates don't necessarily need to be in the same .txt file

  6 件のコメント
Feliciano Döring
Feliciano Döring 2018 年 4 月 19 日
Bob Nbob, no, i use only matlab. That is what i want to do actually, run the program again and again but using different data that is contained in this .txt file and in such a way that it only runs these kind of blocks at a time
Feliciano Döring
Feliciano Döring 2018 年 4 月 19 日
Guillaume, i think that is it, i want to have multiple arrays, so that i can run them through the code individually.

サインインしてコメントする。

採用された回答

njj1
njj1 2018 年 4 月 19 日
編集済み: njj1 2018 年 4 月 19 日

You should import the entire matrix and then begin the splitting process.

A = dlmread('Nest.txt',' '); %this assumes there are no headers or columns that you don't want
k = 1;
while 1
  n = A(1,1); %this is presumably the number of rows that you want to take after the first line
  X{k} = A(2:n+1,:);
  if size(A,1)<n+2
    break
  end
  A = A(n+2:end,:);
  k = k+1;
end

Hopefully this works for you.

  8 件のコメント
njj1
njj1 2018 年 4 月 19 日

If you have data that looks like what you have in your text file, the output from my code is:

X = {[1 1 1; 3 1 1; 2 3 1; 3 2 1], [1 3 1; 2 3 3; 3 1 2]};

I thought this is what you're after...

Feliciano Döring
Feliciano Döring 2018 年 4 月 20 日
編集済み: Feliciano Döring 2018 年 4 月 20 日
Oh wow, thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by