Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7983567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:59:51+00:00 2026-06-04T10:59:51+00:00

I am trying to read in data from a text file and do a

  • 0

I am trying to read in data from a text file and do a 3D plot of it in Matlab. Currently, all I’m getting is a blank plot so my guess is the data is not being stored correctly or at all. Also, I don’t want the 1.000000 at the end of every vector so how can I ignore that? Thanks.

Here is the file:

Blockquote

TechEdge4:<152.266724,173.189377,27.995975>  1.000000
<117.880638,156.116531,27.999983>  1.000000
<129.849899,59.195660,27.999983>  1.000000
<249.321121,60.605404,27.999983>  1.000000
<224.120361,139.072739,28.000668>  1.000000
<171.188950,143.490921,56.933430>  1.000000
<171.188950,143.490921,83.548088>  1.000000
<171.188950,143.490921,27.999985>  1.000000

Here is the code:

file = fopen('C:\Program Files (x86)\Notepad++\testFile.txt'); % open text file

tline = fgetl(file); % read line by line and remove new line characters

% declare empty arrays
CX = [];
CY = [];
CZ = [];

while ischar(tline) % true if tline is a character array

    temp = textscan(tline,'%n%n%n', 'delimiter',',');

    % convert all the cell fields to a matrix
    CX = vertcat(CX, cell2mat(temp));
    CY = vertcat(CY, cell2mat(temp));
    CZ = vertcat(CZ, cell2mat(temp));

    tline = fgetl(file);
end

fclose(file); % close the file

plot3(CX, CY, CZ) % plot the data and label the axises
xlabel('x')
ylabel('y')
zlabel('z') 
grid on
axis square
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:59:52+00:00Added an answer on June 4, 2026 at 10:59 am

    The way your code is running now, your temp variables are blank in each iteration. Replace the textscan line with

    temp = cell2mat(textscan(tline, '<%n,%n,%n>'));
    

    and then the CX, CY, and CZ lines with

    CX = vertcat(CX, temp(1));
    CY = vertcat(CY, temp(2));
    CZ = vertcat(CZ, temp(3));
    

    That should make it work. Of course you will need to handle the first line separately because it has the TechEdge4: thing in it.

    Also I suggest adding a check to make sure temp is non-empty before the vertcats.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read data from a text file and assign it to arrays.
I am trying to read in data from a text file using numpy.loadtxt with
I'm trying to read data from a text file, clear it, and then write
I am trying to read in data from a text file (the time). and
I'm trying to read from a text file to input data to my java
I am trying to read Data from a Text file & storing it inside
I'm trying to read data from an xml file and display it in a
I am trying to read data from a file stream as shown below: fileStream.Read(byteArray,
I'm trying to read data from a binary file and put it into a
I am trying to use a textreader to retrieve data from a text file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.