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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:50:02+00:00 2026-06-07T13:50:02+00:00

This file is an output file whose first line is a header followed by

  • 0

This file is an output file whose first line is a header followed by n rows with data. This first set of data is followed by more similar sets of data with different values.

I want to read the 2nd and 3rd column from this file for all sets of data i.e direction 1, direction 2, etc. Currently I am using the following lines of code inside a function to read the data as shown below:

fid = fopen(output_file); % open the output file

dotOUT_fileContents = textscan(fid,'%s','Delimiter','\n'); % read it as string ('%s') into one big array, row by row
dotOUT_fileContents = dotOUT_fileContents{1};
fclose(fid); %# close the file 

%# find rows containing 'SV' 
data_starts = strmatch('SV',...
    dotOUT_fileContents); % data_starts contains the line numbers wherever 'str2match' is found
nDataRows=data_starts(2)-data_starts(1)-1;
ndata = length(data_starts); % total no. of data values will be equal to the corresponding no. of 'str2match' read from the .out file

%# loop through the file and read the numeric data
for w = 1:ndata

    %# read lines containing numbers
    tmp_str = dotOUT_fileContents(data_starts(w)+1:data_starts(w)+nDataRows); 

    %# convert strings to numbers
    y = cell2mat(cellfun(@(z) sscanf(z,'%f'),tmp_str,'UniformOutput',false)); % store the content of the string which contains data in form of a character
    data_matrix_column_wise(:,w) = y; % convert the part of the character containing data into number

    %# assign output in terms of lag and variogram values 
    lag_column_wise(:,w)=data_matrix_column_wise(2:6:nLag*6-4,w);
    vgs_column_wise(:,w)=data_matrix_column_wise(3:6:nLag*6-3,w); 
end

This function was working good if I didn’t have the stars shown in the output file above. However, one of the output file like the one shown above contained stars and the above code failed in that case. What should be done to take care of the stars inside the data such that I am able to correctly read columns 2 and 3?

  • 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-07T13:50:03+00:00Added an answer on June 7, 2026 at 1:50 pm

    The problem is this part of your code:

    sscanf(z,'%f')
    

    You’re forcing a match to a floating point number, and when it encounters stars it fails. You may be better off replacing that with something like

    textscan(z, '%f %f %f %s %f %f', 'Delimiter', '\t')
    

    and remove the cell2mat and modify the following lines appropriately to test for the presence of strings.

    Alternatively, and this depends on what those stars mean, you could just replace the stars with a zero or something that makes sense, and your current code would work fine.

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

Sidebar

Related Questions

Example input: SERVER_NAME=server1 PROFILE_NAME=profile1 ... Example output: SERVER_NAME=server3 PROFILE_NAME=profile3 ... This file will use
This tail -n 1217060 input.sql > /disk2/mysql_dump/output.sql is not writing to the output file.
I was trying to code this problem in fortran. The output file contains the
This command and output: % find . -name file.xml 2> /dev/null ./a/d/file.xml % So
I have this file which I need to read the first bytes to check
I have a file, whose every 2nd line is of unequal length. I want
I need to process a big data file that contains multi-line records, example input:
I was following this tutorial . I need to use a php file's ouput
Using this file as source, I have a situation where I need to retrieve
Well this file was put in the repo by mistake and was deleted and

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.