read coordinate from a txt file

21 次查看(过去 30 天)
hi, I am working on a bezier surface plotting and I need to read my control points coordinates from a txt file which looks like this:
0.0, 20.0, 3.87
1.3, 30.2, 56,7
7.2, 98.0, 32.5
in the end I need to have somethink like the following but these control points should be in a txt file.
controlpoints=cell(3,3);
controlpoints{1,1}=[ 0.0, 0.0, 65.0];
controlpoints{1,2}=[ 0.0, 76.2, 100.0];
controlpoints{1,3}=[ 0.0, 152.4, 85.0];
controlpoints{2,1}=[ 50.8, 0.0, 50.0];
controlpoints{2,2}=[ 50.8, 76.2, 95.0];
controlpoints{2,3}=[ 50.8, 152.4, 65.0];
controlpoints{3,1}=[ 101.6, 0.0, 85.0];
controlpoints{3,2}=[ 101.6, 76.2, 70.0];
controlpoints{3,3}=[ 101.6, 152.4, 85.0];
I tried to use textscan function but it doesnt work for some reasons.

采纳的回答

dpb
dpb 2020-3-18
textscan is overkill for a simple csv file of the above form --
controlpoints=importdata('YOURTEXTFILE.CSV');
and you'll have the input data as a double array, without the nuicsance of cell array to dereference--far superior.
  1 个评论
burcu bilgic
burcu bilgic 2020-3-18
thank you so much, now I can have my coordinates properly. is there anyway to rearrangethem into the cell format. bc I used them as controlpoints = cell(3,3); format to sent to another function which includes loops inside, now it gives a syntax error like this
Error in Main>BezierSurface (line 48)
X(:,:,k)=Bin.*Bjm.*controlpoints{i+1,j+1}(1);
Error in Main (line 22)
[Xout,Yout,Zout] = BezierSurface(controlpoints,Udirec,Vdirec);

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by