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

  • Home
  • SEARCH
  • 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 8590045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:12:12+00:00 2026-06-11T23:12:12+00:00

I need to load data from file whose file names are enh0.dat, enh1.dat, enh2.dat,

  • 0

I need to load data from file whose file names are enh0.dat, enh1.dat, enh2.dat, …, up to 128 times. So I need to store the file name in a string variable and load data from a file, whose name is stored in the string variable, then store the loaded data in a specified variable for plotting later. But the MATLAB load command loads the data into a variable with a specific name (name of the file containing the data) which does not allow me to automate the use of plot command.

Is it possible to store the name of the file from which I need to load data, in a string variable? I also checked out this
MATLAB newbie: problem reading in file when the file name is stored in a string, but it doesn’t look like it works for me. I get this error when trying to plot the result of textscan:

??? Error using ==> plot Conversion to double from cell is not possible.

This is the code used:

indx = [1:128];
enh_file_cntr = 0;
enh_pre = 'enh';
gain_pre = 'gain';
[enh_file_cntr_str, errmsg1] = sprintf('%d', enh_file_cntr);
enh_file_name = strcat('enh', enh_file_cntr_str, '.dat');
[gain_file_cntr_str, errmsg1] = sprintf('%d', enh_file_cntr);
gain_file_name = strcat('enh', gain_file_cntr_str, '.dat');
fid_enh = fopen(enh_file_name, 'r');
fid_gain = fopen(gain_file_name, 'r');
enh_data = textscan(fid_enh, '%f', 128);
gain_data = textscan(fid_gain, '%f', 128);
subplot(2,3,1);
plot(indx, enh_data, 'b', indx, gain_data, 'r');

If this works I will be incrementing the value of enh_file_cntr in a for loop. How can I fix the above code?

  • 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-11T23:12:13+00:00Added an answer on June 11, 2026 at 11:12 pm

    First: The plot function accepts inputs that are of the numerical matrix type. You are trying to input the output of the textscan function which is a cell array. In your case, the first element of the cell array contains a numerical matrix, but the object is not a numerical matrix itself. To retrieve the numerical matrix stored inside the cell, use:

    enh_data = enh_data{1};
    

    prior to calling the plot function. Note: When accessing the elements of a cell array, always use curly braces, ie {}. When accessing the elements of a numerical matrix, use regular parentheses, ie (). If you have a cell array that contains multiple cells, you can slice it up using ().

    Of course, a cell in a cell array can itself contain a cell array, but maybe don’t worry about this for now 🙂

    Second: Make sure to close any file you open with fopen. ie, once you’ve used textscan, then close the file again with fclose(fid_enh).

    Third, I’m not quite sure I understand what you mean by storing the filename in a string? You appear to be doing exactly that in the code snippet above with the enh_file_name variable?

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

Sidebar

Related Questions

I have a c++ application. I need to load some config data from file.
I need to load (int) data from file. New line separates different data so
I need to load data from source table to Flat file detination(txt). For example
Need to load data from a single file with a 100,000+ records into multiple
Need to load data from a single file with a 100,000+ records into multiple
I need to load data from a File which is located in HDFS and
Hello i need to create a progressView when i load data from my webservice.
I need to load a lot of data fetched from a mysql db in
I need to load a custom function from an extern file but without causing
I need to load a .xml file from a URL adress into an NSData

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.