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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:04:37+00:00 2026-06-17T13:04:37+00:00

I have a few cvs files from which I want to read specific lines

  • 0

I have a few cvs files from which I want to read specific lines and so to collect specific information from them.
While I found that I am able to read these files all good if removing manually a line, I would like to be able to skip this line using some code to avoid going through each of these files and manually removing this line.

Example:
My file looks like this

  • blabla
  • blabla
  • blabla
  • S>
  • blabla
  • blabla
  • nquan = 12
  • blabla

I am reading this file using the following code in matlab:

din = 'C:/example/';
CNVfiles = dir ([din '*.cnv']);
fid = fopen([din CNVfiles], 'r');

I want to be able to get the number ’12’ from the line ‘# nquan = 12’ (which is the number of
column (Ncol) that I will need later),

p = '           ';

while ~isequal(p(1:7),'* nquan')  

    p = fgets(fid);

end

Ncol = str2double(p(11:end));

fclose(fid);

However, it gets me an error stating ‘Index esceed matrix dimension’ at ‘end’ ….when I look at what ‘p’ is, it tells me ‘* S>’ and hence I am guessing that I have an issue when reading that ‘* S>’ line in the files..

When I manually remove that line ‘* S>’, it works all good and I get my Ncol = 12. However, I would like to avoid to do this manually since I have a bunch of cnv files like that.

I was thinking of skipping that line, but do not know how to do that…any ideas what is wrong here? and what can I do to make it works?

Many thanks,

Sophie

  • 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-17T13:04:39+00:00Added an answer on June 17, 2026 at 1:04 pm

    You are getting this error because when your loop reaches the line in your file which contains “* S>”, the value of p is equal to '* S>'. As you can see, p is an array of length 4. When you now try p(1:7), Matlab complains since you are accessing elements that aren’t present.

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

Sidebar

Related Questions

I have few hundred XML files. They are probably generated from/to Excel. I would
I have few values that are DB driven/or coming from other system which i
I have few images on a web page which are fetched from HTTP server
I have few files excluded from build path in eclipse, by right clicking, build
I have few graphic effects on image which i am able to run on
I have few files that resides on a server, im trying to implement a
I have few form which have different behavior in 6i version and 10g version.
I have few MP3 recordings which are hosted on the Amazon S3 server. I
i have few texboxt and dropdownlist, which their id would be something like txtName1,
I have few fields and I want the values inside those fields to get

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.