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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:02:02+00:00 2026-05-15T10:02:02+00:00

I have two cell arrays one called info{} and the other is called data{}

  • 0

I have two cell arrays one called info{} and the other is called data{}
I am reading information in from a text file and am putting the lines into the info{} cell array. When the program finds a blank line I want to to start over with a new info{} cell array and keep inserting the lines until it find another blank line…

global data
global tags
tags{}
data = {};
line = fgets(fid);
counter = 1;
while ischar(line)
   if regexp(line,'/locus_tag=','match','once')
       tags{end+1} = line;

   else

       info{counter} = line;

       if strcmp(newline, line)
           data{end+1} = info;
           info{counter+1}{end+1} = line;
       end
   end
   line = fgets(fid);

end
end

I have included some code it doesn’t work but it is what I have gotten so far.I think I think I understand the algorithm I need to use to do this but am having some trouble implementing it. Any ideas?

In the end I want something that looks like

data = { {info1} {info2} {info3}... {infon}
  • 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-05-15T10:02:03+00:00Added an answer on May 15, 2026 at 10:02 am

    I think something like this will work, although I can’t know for sure without a sample data file:

    %# Load all the lines from the file:
    
    allLines = {};            %# An empty cell array to store all lines in the file
    fid = fopen('data.txt');  %# Open the file
    nextLine = fgetl(fid);    %# Get the next line
    while ischar(nextLine)                %# Check for an end-of-file condition
      allLines = [allLines; {nextLine}];  %# Add the line to allLines
      nextLine = fgetl(fid);              %# Get the next line
    end
    fclose(fid);              %# Close the file
    
    %# Remove any trailing whitespace from the lines:
    
    allLines = deblank(allLines);
    
    %# Find tags and remove them:
    
    index = regexp(allLines,'/locus_tag=','once');  %# Index of matches
    index = ~cellfun(@isempty,index);  %# Find where index isn't empty
    tags = allLines(index);            %# Get cells with tags in them
    allLines(index) = [];              %# Remove cells with tags
    
    %# Find empty lines and group non-empty spans into cells:
    
    index = cellfun(@isempty,allLines);  %# Find empty lines
    allLines(index) = [];                %# Remove cells with empty lines
    counts = diff([0; find(index); numel(index)+1]);  %# Get the number of lines
    counts = counts(counts > 1)-1;                    %#   to put in each group 
    data = mat2cell(allLines,counts);    %# Group the non-empty lines
    

    Some of the functions used above: FGETL, DEBLANK, REGEXP, CELLFUN, MAT2CELL.

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

Sidebar

Related Questions

I have two columns in my NSOutlineView. One is a Text and image cell
I have two table views, when user clicks one cell of the first, second
I have two table cells, with dynamic content. Table cell one works fine, when
I have two classes (MVC view model) which inherits from one abstract base class.
I have two cell arrays of strings, and I want to check if they
I have a cell array in Matlab: strings = {'one', 'two', 'three'}; How can
I have two worksheets, one which is used to filter the other. Using VBA
In my iPhone app, In Table view I have Two labels in one cell..
I have two cell arrays that are <12x1 cell> and they are labeled A
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two

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.