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 8641843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:38:02+00:00 2026-06-12T11:38:02+00:00

I have a CSV file which contains numbers,date and text. I have to extract

  • 0

I have a CSV file which contains numbers,date and text. I have to extract the column which contain the text.

For example, sample csv file look like

1-1-2000,1,2.3,TRUE    
2-1-2000,1,2.3,FALSE
  1. I want to extract the column containing the TRUE/FALSE values.

  2. I want to convert the TRUE into 1 and FALSE into 0.

Please suggest some functions and sample code to do this

  • 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-12T11:38:03+00:00Added an answer on June 12, 2026 at 11:38 am

    You can try this:

    [~,~,~,bools] = textread('filename.csv', '%s%d%f%s', 'delimiter', ',');
    
    bools = cellfun(@strtrim, bool, 'uniformoutput', false);
    bools = strcmp(bools, 'TRUE');
    

    the line with strtrim might not be necessary if you know beforehand that there are never any trailing spaces. The line with strcmp outputs a logical array for all entries that string-compare to the literal TRUE, which implies that all other entries are false. Meaning:

    1-1-2000,1,2.3,TRUE    
    2-1-2000,1,2.3,BANANAS
    

    would produce the same logical vector. If you also want to explicitly compare to the string literal FALSE, use something like this:

    a = NaN(size(bools));
    a(strcmp(bools, 'TRUE'))  = 1;
    a(strcmp(bools, 'FALSE')) = 0;
    if ~any(isnan(a))
        bools = logical(a);
        clear a
    else
        %# handle the error
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CSV file (exported data from iWork Numbers) which contains of a
I have a csv file which contains the numbers of buttons. I want to
Suppose we have a csv file(>5GB) which contains Employee name and Age column. The
I have a big text file which contains similar entries like this My goal
I have a Testing project that contains a csv file which a webtest uses
I have .zip file which contain csv data. I am reading .zip file using
I have a CSV file the first row of which contains the variables names
I have a CSV file the first row of which contains the variables names
I have a large CSV file, approx 10 MB in size, which contains all
I have a CSV file which contains an ID and several other columns. I

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.