필터 지우기
필터 지우기

read coordinate from a txt file

조회 수: 5 (최근 30일)
burcu bilgic
burcu bilgic 2020년 3월 18일
댓글: burcu bilgic 2020년 3월 18일
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