How to read an input text file having multiple values??

0 0 0 0.5 0 0.049406182 1 0 0.097122055 0 0.51 0 0.5 0.51 0.049406182 1 0.51 0.097122055
1.5 0 0.143149239 2 0 0.187489294 1.5 0.51 0.143149239 2 0.51 0.187489294
Read these values of x1,y1,z1 x2,y2,z2 x3,y3,z3....and so on

回答 (2 件)

KSSV
KSSV 2018 年 10 月 10 日

0 投票

REead about load, importdata, textscan. If your file has only numbers then load / importdata should work.

2 件のコメント

Virajan Verma
Virajan Verma 2018 年 10 月 10 日
Can u give me one example of loading x1,y1,z1 and x2,y2,z2??
KSSV
KSSV 2018 年 10 月 10 日
Attach your file....

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

Virajan Verma
Virajan Verma 2018 年 10 月 10 日

0 投票

Here it is

15 件のコメント

KSSV
KSSV 2018 年 10 月 10 日
fid = fopen('inputxyzz.txt','r');
S = textscan(fid,'%f %f %f') ;
x = S{1} ; y = S{2} ; z = S{3} ;
fclose(fid) ;
scatter3(x,y,z,10,z,'filled')
Virajan Verma
Virajan Verma 2018 年 10 月 10 日
Thanks. But it is loading x,y,z column wise. I want x1,y1,z1....x2,y2,z2...x3,y3,z3..and so on row wise.How to do that??
KSSV
KSSV 2018 年 10 月 10 日
Friend......it is loading in the way what you want only...
coor = [x y z] ;
coor(1,:) % this igves you (x1,y1,z1)
coor(7,:) % this gives you (x7,y7,z7)
coor(i,:) % this gives you (xi,yi,zi) ;
Virajan Verma
Virajan Verma 2018 年 10 月 10 日
So i should write coor(i,:) or coor(1,:),coor(2,:)...and so on??
KSSV
KSSV 2018 年 10 月 10 日
yes.....
Virajan Verma
Virajan Verma 2018 年 10 月 10 日
First one or second one(see my previous comment).
KSSV
KSSV 2018 年 10 月 10 日
:(
I mean to say i = 1,2,....n
Virajan Verma
Virajan Verma 2018 年 10 月 10 日
編集済み: KSSV 2018 年 10 月 10 日
Still not working.I have written like this:
for i=1:1:122
fid = fopen('inputxyzz.txt','r');
S = textscan(fid,'%f %f %f') ;
x = S{1} ; y = S{2} ; z = S{3} ;
fclose(fid) ;
scatter3(x,y,z,10,z,'filled')
coor = [x y z] ;
coor(i,:)
end
ERROR: undefined function x1.(Lxn_dash=N1*x1+N2*x2+N3*x3; in this line)
madhan ravi
madhan ravi 2018 年 10 月 10 日
fid = fopen('inputxyzz.txt'','r');
S = textscan(fid,'%f %f %f') ;
x = S{1} ; y = S{2} ; z = S{3} ;
fclose(fid) ; scatter3(x,y,z,10,z,'filled')
coor = [x y z] ;
for i=1:1:122
coor(i,:)
end
Virajan Verma
Virajan Verma 2018 年 10 月 10 日
Still not working. Same error, undefined x1. It is not loading up the values i think. But a graph is showing. Dont know why??
KSSV
KSSV 2018 年 10 月 10 日
@ Virajan Verma dont blindly follow the code........read what the function does....the doubts you are asking are very silly.
fid = fopen('inputxyzz.txt','r');
S = textscan(fid,'%f %f %f') ;
x = S{1} ; y = S{2} ; z = S{3} ;
fclose(fid) ;
scatter3(x,y,z,10,z,'filled')
coor = [x y z] ;
for i = 1:length(X)
coor(i,:)
end
Virajan Verma
Virajan Verma 2018 年 10 月 10 日
@KSSV Yes i know i am asking silly question. I havnt done coding previously, so i am getting stuck way too many times. I tried ur above expression but the error is still there.
KSSV
KSSV 2018 年 10 月 10 日
No one done coding earlier, at the time of their career beginning .....one has to learn.....you are showing a part of your code...you are not showing full code.
Lxn_dash=N1*x1+N2*x2+N3*x3;
Obviously the above lines show error. Where you have defined (x1,x2,x3)????They are not defined....they are in the coor or (x,y,z) ..you need to provide the indices of it. May be like this:
Lxn_dash=N1*x(1)+N2*x(2)+N3*x(3);
Here, you will be having nodal connectivity data, with this nodal connectivity daya you will be getting the vertices of every element.
Virajan Verma
Virajan Verma 2018 年 10 月 11 日
According to you, how many values of Lxn_dash should come??
KSSV
KSSV 2018 年 10 月 11 日
It depends on the number of elements and number of nodes in each element.
Thanks officially for accepting the answer.

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

タグ

質問済み:

2018 年 10 月 10 日

コメント済み:

2018 年 10 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by