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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:26:29+00:00 2026-06-09T06:26:29+00:00

I am attempting to create a script which asks the user for the filename

  • 0

I am attempting to create a script which asks the user for the filename of a txt file whose contents will later be plotted.

filename = input('What is the filename (without the extension) e.g. RCP6: ','s');
if isempty(filename)
    filename=input('What is the filename (without the extension) e.g. RCP6: ','s');
end

ext =  input('What is the filetype (extension) e.g. .txt: ','s');
if isempty(ext)
    ext=input('What is the filetype (extension) e.g. .txt: ','s');
end

filew = strcat(filename,ext)

load(filew)
A = filename
Y = A(:,1)
E = A(:,2)

plot(Y,E)
xlabel('calendar year')
ylabel('annual fossil carbon emissions (GtC)')

As written, the code correctly concatenates filename and ext, however, it does not appear that load (filew) correctly loads that file, since given a filename = RCP3PD for example, Y = R and E = C, instead of Y storing the first column of values from RCP3PD.txt?

Any Suggestions? I have seen other “load file from string” threads make reference to the sprintf() function – would that apply here?

  • 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-09T06:26:30+00:00Added an answer on June 9, 2026 at 6:26 am

    When you load the data you need to save it as something. So :

    load(filew)
    

    Should look like

    data = load(filew);
    

    Then to access your variables simply use:

    A = data.A; % assume that data is a struct with a field named A
    Y = A(:,1);
    E = A(:,2);
    

    Other Thoughts

    You might consider changing the logic for typing a file name to something like this:

    valid = 0;
    while(valid==0)
      filename = input('What is the filename (without the extension) e.g. RCP6: ','s');
      ext =  input('What is the filetype (extension) e.g. .txt: ','s');
      if exist([filename, ext], 'file')
        valid = 1;
      end
    end
    

    Instead of checking to see if the filename is empty check to see if the user has provided a filename/extension pair that actually exist. If not then keep asking until they do.

    If you want to get fancy you might use uigetfile instead of asking the user to type in a filename. This presents the user with a file picker window and this way you know that they have picked a valid file. Additionally it allows you to filter what files the user can chose.

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

Sidebar

Related Questions

I'm attempting to create an automated script on my own site which logs into
I'm attempting to create a CustomControl which will have various properties affected by an
I am attempting to create a top-level script that will call about 35+ other
I'm attempting to create an ASP.NET/C# page that runs a PowerShell script that will
I am attempting to create a script that wraps a Groovy class that will
I am currently attempting to create a bash script that will check inside of
I'm attempting to create an automated bash script that fills up a file with
I am currently attempting to create an Inno script installer which requests a list
I am attempting to create a shell script using Node.js similar to packages like
I'm attempting to create a table for monitoring purposes using the following script: $w3wppriv

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.