read coordinate from a txt file

21 vues (au cours des 30 derniers jours)
burcu bilgic
burcu bilgic le 18 Mar 2020
Commenté : burcu bilgic le 18 Mar 2020
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.

Réponse acceptée

dpb
dpb le 18 Mar 2020
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 commentaire
burcu bilgic
burcu bilgic le 18 Mar 2020
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);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Visual Exploration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by