Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

[Matlab] How to use inputdlg string variable in text file?

  1. Oct 26, 2014 #1
    I am trying to display the input that I enter into the dialog box from "inputdlg" function into a text file.

    This is what I've so far:

    Code (Text):
    prompt={['What is your name?']};
    title = 'Name Machine';
    answer = inputdlg(prompt, title);
    name = answer{1};
    fileID = fopen('NameMachineFive.txt', 'w');
    fprintf(fileID,['His name is %s.', name]);
    fclose(fileID);
    The input dialog shows up and asks 'What is your name'? I enter it in, and then it closes. I go open the text file 'NameMachineFive.txt' and I get:

    Code (Text):
    His name is
    But when I enter into Matlab:

    Code (Text):
    name
    I get the name that I entered into the 'inputdlg' dialog box.

    So my question is:

    ]How would I fix the code to get the name input entered into the text file?

    I'd highly appreciate the assistance.
     
  2. jcsd
  3. Oct 28, 2014 #2

    DrClaude

    User Avatar

    Staff: Mentor

    Remove the square brackets in the fprintf:
    Code (Matlab M):

    fprintf(fileID,'His name is %s.', name);
     
     
  4. Nov 11, 2014 #3
    Thank you very much DrClaude.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: [Matlab] How to use inputdlg string variable in text file?
Loading...